fn

resolveFetchOptions

v0.0.1

Merges 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

ParameterTypeDescription
requestFetchRequest
inputFetchOptions | undefined
defaultsFetchOptions | undefined

Returns

ResolvedFetchOptions
PropertyTypeDescription
headersHeaders
baseURL?stringBase URL prepended to all relative request URLs
body?RequestInit['body'] | object | nullRequest 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?booleanSuppress 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) => TCustom response parser — overrides built-in JSON.parse
responseType?RExpected response format — drives body parsing
duplex?'half'Enable duplex streaming. Automatically set to "half" when a ReadableStream is used as body.
timeout?numberRequest timeout in milliseconds. Uses AbortSignal.timeout internally.
retry?number | falseNumber 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