Interface FetchClientOptions

Resilience configuration for a fetch client

interface FetchClientOptions {
    baseUrl?: string;
    circuitBreaker?: CircuitBreakerConfig;
    consoleLogHttpIssues?: boolean;
    defaultHeaders?: HeadersInit;
    defaultHeadersByMethod?: Record<MethodName, HeadersInit>;
    defaultSkipFailOnErrorCode?: boolean;
    fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>);
    parallelRequests?: ParallelRequestsConfig;
    retries?: number | RetryConfig;
    timeoutRequest?: number;
    timeoutTotal?: number;
}

Properties

baseUrl?: string
circuitBreaker?: CircuitBreakerConfig
consoleLogHttpIssues?: boolean
defaultHeaders?: HeadersInit

Set default headers for each request.

defaultHeadersByMethod?: Record<MethodName, HeadersInit>

Set default headers for each request of a specified method type. These are merged with defaultHeaders, if they are set as well. (set a header to undefined or "" to remove it)

defaultSkipFailOnErrorCode?: boolean

By default, status codes >= 400 are treated as errors, other than in standard fetch. This can be disabled and the standard fetch behaviour restored, by setting this flag. Besides the client-wide setting, there is also the possibility to set skipFailOnErrorCode per request.

fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>)

Defaults to globalThis.fetch / window.fetch

parallelRequests?: ParallelRequestsConfig
retries?: number | RetryConfig
timeoutRequest?: number

This is a per-request timeout not taking into account possible retries. The total duration of a call to client.fetch() can therefore exceed this limit, if retries are configured.

timeoutTotal?: number

This is an overall timeout after considering retries. The total duration of a fetch call should never exceed this limit.