Member Junction
    Preparing search index...

    Per-instance defaults and hooks for HttpClient.

    The three hooks replace what axios interceptors did, with one important difference: they are plain options on the instance rather than entries appended to a mutable global chain, so what a given client does is visible at its construction site and cannot be changed from elsewhere.

    axios here
    interceptors.request.use(fn) HttpClientOptions.OnRequest
    interceptors.response.use(onOk) HttpClientOptions.OnResponse
    interceptors.response.use(_, onErr) HttpClientOptions.OnRetry
    interface HttpClientOptions {
        BaseURL?: string;
        BasicAuth?: { Password: string; Username: string };
        Headers?: Record<string, string>;
        MaxRedirects?: number;
        MaxRetries?: number;
        OnRequest?: (
            config: HttpRequestConfig,
        ) => HttpRequestConfig | Promise<HttpRequestConfig>;
        OnResponse?: (response: HttpResponse<unknown>) => void | Promise<void>;
        OnRetry?: (error: HttpError, attempt: number) => boolean | Promise<boolean>;
        Timeout?: number;
        ValidateUrl?: boolean;
    }
    Index

    Properties

    BaseURL?: string

    Prefix applied to every relative request URL.

    BasicAuth?: { Password: string; Username: string }

    Default HTTP Basic credentials applied to every request.

    Headers?: Record<string, string>

    Headers merged under each request's own headers.

    MaxRedirects?: number

    Default maximum redirect hops. Default: 5.

    MaxRetries?: number

    Maximum retry attempts allowed when OnRetry asks for one. Default: 3.

    OnRequest?: (
        config: HttpRequestConfig,
    ) => HttpRequestConfig | Promise<HttpRequestConfig>

    Called before each request with the fully merged config; return the config to actually send. The replacement for an axios request interceptor — this is where token injection, request signing, and per-request query defaults belong.

    Treat the incoming config as immutable and return a new object; it is re-derived on every retry attempt, so a token read here is always current rather than captured at construction.

    OnRequest: (config) => ({
    ...config,
    Headers: { ...config.Headers, Authorization: `Bearer ${this.getAccessToken()}` },
    })
    OnResponse?: (response: HttpResponse<unknown>) => void | Promise<void>

    Called after each successful response. Observation only: whatever this does, the response is still returned to the caller unchanged. Replaces the success half of an axios response interceptor — logging, metrics, and rate-limit headroom tracking belong here.

    OnResponse: (response) => {
    const remaining = response.Headers['x-rate-limit-remaining'];
    if (remaining) LogStatus(`Rate limit remaining: ${remaining}`);
    }
    OnRetry?: (error: HttpError, attempt: number) => boolean | Promise<boolean>

    Called when a request fails. Return true to retry, false to let the error propagate. Replaces the error half of an axios response interceptor — 429 back-off, and one-shot token refresh on a 401, belong here.

    Retries are bounded by MaxRetries (default 3) so a hook that always returns true cannot loop forever. Await the back-off inside the hook; the retry fires as soon as it resolves, and OnRequest runs again first, so a refreshed token is picked up automatically.

    Only an HttpError reaches this hook — an SSRFError is a security decision and is never retried.

    OnRetry: async (error, attempt) => {
    if (error.Status !== 429) return false;
    const retryAfter = Number(error.Headers['retry-after']) || 2 ** attempt;
    await new Promise((r) => setTimeout(r, retryAfter * 1000));
    return true;
    }
    Timeout?: number

    Default request timeout in milliseconds. Default: 30000.

    ValidateUrl?: boolean

    When true, every request runs through the SSRF guard. Default: false.