Documentation / zerotal / client / ApiClientConfig
Interface: ApiClientConfig
Defined in: packages/client/src/ApiClient.ts:109
Extended by
Properties
baseUrl?
optionalbaseUrl?:string
Defined in: packages/client/src/ApiClient.ts:111
Base URL prepended to every request path, e.g. 'https://api.example.com'.
headers?
optionalheaders?:Record<string,string>
Defined in: packages/client/src/ApiClient.ts:113
Default headers sent with every request (e.g. Authorization).
token?
optionaltoken?:TokenSource
Defined in: packages/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?
optionalwithCredentials?:boolean
Defined in: packages/client/src/ApiClient.ts:121
Send credentials (cookies) with every request — sets credentials: 'include'.
csrf?
optionalcsrf?:boolean| {cookie?:string;header?:string; }
Defined in: packages/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?
optionaltimeout?:number
Defined in: packages/client/src/ApiClient.ts:129
Default per-request timeout in ms (0/omitted = no timeout).
retry?
optionalretry?:number|RetryOptions
Defined in: packages/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?
optionalonError?: (error) =>void|Promise<void>
Defined in: packages/client/src/ApiClient.ts:137
Called for every non-2xx response before the error is thrown.
Parameters
error
Returns
void | Promise<void>
onForbidden?
optionalonForbidden?: (error) =>void|Promise<void>
Defined in: packages/client/src/ApiClient.ts:139
Called when a request receives 403 Forbidden.
Parameters
error
Returns
void | Promise<void>
onRequest?
optionalonRequest?:RequestInterceptor|RequestInterceptor[]
Defined in: packages/client/src/ApiClient.ts:141
One or more request interceptors executed in order before every fetch.
onResponse?
optionalonResponse?:ResponseInterceptor|ResponseInterceptor[]
Defined in: packages/client/src/ApiClient.ts:143
One or more response interceptors executed in order after every successful (2xx) response.
onUnauthorized?
optionalonUnauthorized?: (error,retry) =>void|Promise<unknown>
Defined in: packages/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
retry
(headerOverrides?) => Promise<unknown>
Returns
void | Promise<unknown>
Example
onUnauthorized: async (err, retry) => retry({ Authorization: `Bearer ${await refresh()}` }),
circuitBreaker?
optionalcircuitBreaker?:CircuitBreaker|CircuitBreakerOptions
Defined in: packages/client/src/ApiClient.ts:156
Attach a circuit breaker (instance to share, or options to create a dedicated one).