fn
resolveFetchOptions
v0.0.1Merges per-request options with global defaults
Signature
ts
export function resolveFetchOptions<R extends ResponseType = 'json', T = unknown>(
request: FetchRequest,
input: FetchOptions<R, T> | undefined,
defaults: FetchOptions | undefined,
): ResolvedFetchOptions<R, T>;Parameters
| Parameter | Type | Description |
|---|---|---|
request | FetchRequest | — |
input | FetchOptions | undefined | — |
defaults | FetchOptions | undefined | — |
Returns
ResolvedFetchOptions| Property | Type | Description |
|---|---|---|
headers | Headers | — |
baseURL? | string | Base URL prepended to all relative request URLs |
body? | RequestInit['body'] | object | null | Request body. BodyInit values (string, Blob, FormData, streams, …) are
sent as-is; any other object or array is JSON-serialized. Typed as object
rather than Record<string, unknown> so a named interface assigns
directly — interfaces carry no implicit index signature and would otherwise
force every caller to cast the body. |
ignoreResponseError? | boolean | Suppress throwing on 4xx/5xx responses |
query? | Record<string, string | number | boolean | null | undefined> | URL query parameters serialized and appended to the request URL |
params? | Record<string, string | number | boolean | null | undefined> | — |
parseResponse? | (responseText: string) => T | Custom response parser — overrides built-in JSON.parse |
responseType? | R | Expected response format — drives body parsing |
duplex? | 'half' | Enable duplex streaming. Automatically set to "half" when a ReadableStream is used as body. |
timeout? | number | Request timeout in milliseconds. Uses AbortSignal.timeout internally. |
retry? | number | false | Number of retry attempts on failure, or false to disable. Defaults to 1 for non-payload methods. |
retryDelay? | number | ((context: FetchContext<T, R>) => number) | Delay in milliseconds between retries, or a function receiving the context |
retryStatusCodes? | readonly number[] | HTTP status codes that trigger a retry. Defaults to [408, 409, 425, 429, 500, 502, 503, 504]. |
onRequest? | ReadonlyArrayable<FetchHook<FetchContext<T, R>>> | Called before the request is sent |
onRequestError? | ReadonlyArrayable<FetchHook<FetchContext<T, R> & { error: Error }>> | Called when the request itself throws (e.g. network error, timeout) |
onResponse? | ReadonlyArrayable<FetchHook<FetchContext<T, R> & { response: FetchResponse<T> }>> | Called after a successful response is received and parsed |
onResponseError? | ReadonlyArrayable<FetchHook<FetchContext<T, R> & { response: FetchResponse<T> }>> | Called when the response status is 4xx or 5xx |