Libraries
    Preparing search index...

    Interface ClientOptions

    Configuration for createClient.

    interface ClientOptions {
        baseUrl?: string;
        fetch?: (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>;
        getToken?: () => string | null;
        headers?: Record<string, string>;
        hooks?: ClientHooks;
        middlewares?: Middleware[];
        onUnauthorized?: () => void;
        subscriptionReconnect?: SubscriptionReconnectOptions;
    }
    Index

    Properties

    baseUrl?: string

    Base URL prepended to every request path. Defaults to '' (same origin).

    `'https://api.example.com'`
    
    fetch?: (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>

    Custom fetch implementation. Defaults to the global fetch. Useful for testing or server-side rendering where a polyfill is needed.

    Type Declaration

      • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
      • Parameters

        • input: URL | RequestInfo
        • Optionalinit: RequestInit

        Returns Promise<Response>

    getToken?: () => string | null

    Returns the current authentication token, or null if unauthenticated. When a non-null value is returned it is sent as a Bearer token in the Authorization header.

    headers?: Record<string, string>

    Additional headers sent with every request.

    hooks?: ClientHooks

    Lifecycle hooks invoked at various stages of a request.

    const client = createClient(api, {
    hooks: {
    beforeRequest: [(req) => { console.log('→', req.url); }],
    afterResponse: [(req, res) => { console.log('←', res.status); }],
    },
    });
    middlewares?: Middleware[]

    Middleware functions that wrap the fetch call. Applied in array order — the first middleware is the outermost wrapper.

    import { retry } from '@cleverbrush/web/retry';
    import { timeout } from '@cleverbrush/web/timeout';

    const client = createClient(api, {
    middlewares: [retry(), timeout({ timeout: 10000 })],
    });
    onUnauthorized?: () => void

    Called when a 401 Unauthorized response is received. Typically used to clear stored tokens and redirect to a login page.

    subscriptionReconnect?: SubscriptionReconnectOptions

    Default reconnection options for all WebSocket subscriptions created by this client.

    Individual subscription calls can override these options by passing a reconnect argument. Pass reconnect: false at the call site to disable reconnection for a specific subscription even when a global default is set.

    const client = createClient(api, {
    baseUrl: 'https://api.example.com',
    subscriptionReconnect: {
    maxRetries: 10,
    backoffLimit: 60_000,
    jitter: true,
    },
    });