Skip to main content
zerotal

Documentation


Documentation / @zerotal/client / index / ApiClientConfig

Interface: ApiClientConfig

Defined in: client/src/ApiClient.ts:109

Extended by

Properties

baseUrl?

optional baseUrl?: string

Defined in: client/src/ApiClient.ts:111

Base URL prepended to every request path, e.g. 'https://api.example.com'.


headers?

optional headers?: Record<string, string>

Defined in: client/src/ApiClient.ts:113

Default headers sent with every request (e.g. Authorization).


token?

optional token?: TokenSource

Defined in: client/src/ApiClient.ts:119

Bearer token attached as Authorization: Bearer <token> when no Authorization header is already present. May be a string or a (possibly async) resolver. Update at runtime with ApiClient.setToken.


withCredentials?

optional withCredentials?: boolean

Defined in: client/src/ApiClient.ts:121

Send credentials (cookies) with every request — sets credentials: 'include'.


csrf?

optional csrf?: boolean | { cookie?: string; header?: string; }

Defined in: client/src/ApiClient.ts:127

Attach the CSRF/XSRF token to mutating requests: reads the XSRF-TOKEN cookie and sends it as X-XSRF-TOKEN (the SPA/session flow). Defaults to true when withCredentials is set. Customize the cookie/header names with an object.


timeout?

optional timeout?: number

Defined in: client/src/ApiClient.ts:129

Default per-request timeout in ms (0/omitted = no timeout).


retry?

optional retry?: number | RetryOptions

Defined in: client/src/ApiClient.ts:135

Default retry policy. 2 retries idempotent requests on network errors / 5xx / 429 with exponential backoff (honoring Retry-After); pass RetryOptions to tune, or omit to disable. Per-request retry overrides this.


onError?

optional onError?: (error) => void | Promise<void>

Defined in: client/src/ApiClient.ts:137

Called for every non-2xx response before the error is thrown.

Parameters

error

ApiClientError

Returns

void | Promise<void>


onForbidden?

optional onForbidden?: (error) => void | Promise<void>

Defined in: client/src/ApiClient.ts:139

Called when a request receives 403 Forbidden.

Parameters

error

ApiClientError

Returns

void | Promise<void>


onRequest?

optional onRequest?: RequestInterceptor | RequestInterceptor[]

Defined in: client/src/ApiClient.ts:141

One or more request interceptors executed in order before every fetch.


onResponse?

optional onResponse?: ResponseInterceptor | ResponseInterceptor[]

Defined in: client/src/ApiClient.ts:143

One or more response interceptors executed in order after every successful (2xx) response.


onUnauthorized?

optional onUnauthorized?: (error, retry) => void | Promise<unknown>

Defined in: client/src/ApiClient.ts:151

Called when a request receives 401 Unauthorized. Receives the error and a retry function (optionally with header overrides) to re-execute the request once.

Parameters

error

ApiClientError

retry

(headerOverrides?) => Promise<unknown>

Returns

void | Promise<unknown>

Example

onUnauthorized: async (err, retry) => retry({ Authorization: `Bearer ${await refresh()}` }),

circuitBreaker?

optional circuitBreaker?: CircuitBreakerOptions | CircuitBreaker

Defined in: client/src/ApiClient.ts:156

Attach a circuit breaker (instance to share, or options to create a dedicated one).