Skip to main content
Version: v8.0.0

Request

Request is a class that represents a request sent to the server. It contains all the necessary information to make a request, like endpoint, method, headers, data, and much more. It is executed at any time via methods like send or exec .

We can set it up with options like endpoint, method, headers and more. We can choose some of advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.


Import
import { Request } from "@hyper-fetch/core"

Parameters

class Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext> {
constructor(client: Client, requestOptions: ClientRequestOptions<Endpoint, Client>, initialRequestConfiguration: RequestConfigurationType<Payload, Endpoint extends string ? ExtractUrlParams<Endpoint<Endpoint>> : never, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>) {};
used: boolean;
unstable_mock: { config: MockerConfigType; fn: (options: { request: RequestInstance; requestId: string }) => MockResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>> };
unstable_hasQuery: HasQuery;
unstable_hasPayload: HasPayload;
unstable_hasParams: HasParams;
unstable_hasMutationContext: MutationContext;
staleTime: number;
scope: null | string;
retryTime: number;
retry: number;
requestOptions: ClientRequestOptions<Endpoint, Client>;
queued: boolean;
queryParams: EmptyTypes | QueryParams;
queryKey: string;
payload: PayloadType<Payload>;
params: EmptyTypes | ExtractUrlParams<Endpoint>;
options: ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>;
offline: boolean;
method: ExtractAdapterMethodType<ExtractClientAdapterType<Client>>;
isMockerEnabled: boolean;
initialRequestConfiguration: RequestConfigurationType<Payload, Endpoint extends string ? ExtractUrlParams<Endpoint<Endpoint>> : never, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>;
headers: HeadersInit;
endpoint: Endpoint;
deduplicateTime: null | number;
deduplicate: boolean;
client: Client;
cancelable: boolean;
cacheTime: number;
cacheKey: string;
cache: boolean;
auth: boolean;
abortKey: string;
$hooks: RequestHooks<RequestInstance>;
exec() => RequestSendType<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>>;
send() => RequestSendType<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>>;
abort() => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
clearMock() => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
clone<NewData, NewParams, NewQueryParams>(configuration?: RequestConfigurationType<Payload, EmptyTypes | ExtractUrlParams<Endpoint>, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, NewData, NewParams, NewQueryParams, MutationContext>;
dehydrate(config?: { override?: boolean; response?: ResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>> }) => undefined | HydrateDataType<Response, (LocalError | ExtractClientGlobalError<Client>), ExtractClientAdapterType<Client>>;
read() => undefined | ResponseType<Response, (LocalError | ExtractClientGlobalError<Client>), ExtractClientAdapterType<Client>>;
setAbortKey(abortKey: string) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setAuth(auth: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setCache(cache: undefined | boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setCacheKey(cacheKey: string) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setCacheTime(cacheTime: undefined | number) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setCancelable(cancelable: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setDeduplicate(deduplicate: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setDeduplicateTime(deduplicateTime: number) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setHeaders(headers: HeadersInit) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setMock(fn: (options: { request: Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, undefined>; requestId: string }) => SyncOrAsync<MockResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>>>, config: MockerConfigType) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setMockingEnabled(isMockerEnabled: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setOffline(offline: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setOptimistic<Ctx>(callback: OptimisticCallback<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, Ctx>) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, Ctx>;
setOptions(options: ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, true, MutationContext>;
setParams<P>(params: P) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, P extends null ? false : true, HasQuery, MutationContext>;
setPayload<P>(payload: P) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, P extends null ? false : true, HasParams, HasQuery, MutationContext>;
setPayloadMapper<MappedPayload>(payloadMapper: (data: Payload) => MappedPayload) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setQueryKey(queryKey: string) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setQueryParams(queryParams: QueryParams) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, true, MutationContext>;
setQueued(queued: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setRequestMapper<NewRequest>(requestMapper: RequestMapper<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, NewRequest>) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setResponseMapper<MappedResponse>(responseMapper?: ResponseMapper<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, MappedResponse>) => Request<MappedResponse extends ResponseType<R, any, any> ? R : Response, Payload, QueryParams, MappedResponse extends ResponseType<any, E, any> ? E : LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setRetry(retry: undefined | number) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setRetryOnError(callback: RetryOnErrorCallbackType<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, undefined>>) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setRetryTime(retryTime: undefined | number) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setScope(scopeId: string) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setStaleTime(staleTime: undefined | number) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
setUsed(used: boolean) => Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>;
toJSON() => RequestJSON<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>>;
fromJSON<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery>(client: NewClient, json: RequestJSON<Request<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery, undefined>>) => Request<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery, undefined>;
}
Parameters
NameTypeDescription
client
Client
requestOptions
ClientRequestOptions<Endpoint, Client>
initialRequestConfiguration
RequestConfigurationType<Payload, Endpoint extends string ? ExtractUrlParams<Endpoint<Endpoint>> : never, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>

Properties

$hooks

Instance-level lifecycle hooks. These callbacks fire for every send() / exec() call made on this request instance (and its clones), without needing to pass them to send() each time. Useful for cross-cutting concerns like logging, analytics, or toast notifications.

Each method registers a callback and returns an unsubscribe function. Multiple listeners per hook are supported.

Type
RequestHooks<RequestInstance>

abortKey

Type
string

auth

Type
boolean

cache

Type
boolean

cacheKey

Type
string

cacheTime

Type
number

cancelable

Type
boolean

client

Type
Client

deduplicate

Type
boolean

deduplicateTime

Type
null | number

endpoint

Type
Endpoint

headers

Type
HeadersInit

initialRequestConfiguration

Type
RequestConfigurationType<Payload, Endpoint extends string ? ExtractUrlParams<Endpoint<Endpoint>> : never, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>

isMockerEnabled

Type
boolean

method

Type
ExtractAdapterMethodType<ExtractClientAdapterType<Client>>

offline

Type
boolean

options

Type
ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>

params

Type
EmptyTypes | ExtractUrlParams<Endpoint>

payload

Type
PayloadType<Payload>

queryKey

Type
string

queryParams

Type
EmptyTypes | QueryParams

queued

Type
boolean

requestOptions

Type
ClientRequestOptions<Endpoint, Client>

retry

Type
number

retryTime

Type
number

scope

Type
null | string

staleTime

Type
number

unstable_hasMutationContext

Type
MutationContext

unstable_hasParams

Type
HasParams

unstable_hasPayload

Type
HasPayload

unstable_hasQuery

Type
HasQuery

unstable_mock

Type
{ config: MockerConfigType; fn: (options: { request: RequestInstance; requestId: string }) => MockResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>> }

used

Type
boolean

Methods

abort()

Abort all in-flight requests sharing this request's abort key.

Preview
abort()
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

clearMock()

Remove any attached mock handler and disable mocking for this request.

Preview
clearMock()
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

clone()

Create a new request instance with optional configuration overrides. Used internally by all setter methods.

Preview
clone<NewData, NewParams, NewQueryParams>(configuration: RequestConfigurationType<Payload, EmptyTypes | ExtractUrlParams<Endpoint>, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>)
Parameters
Parameters
NameTypeDescription
configuration
RequestConfigurationType<Payload, EmptyTypes | ExtractUrlParams<Endpoint>, QueryParams, Endpoint, ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>, ExtractAdapterMethodType<ExtractClientAdapterType<Client>>>
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, NewData, NewParams, NewQueryParams, MutationContext>

dehydrate()

Extract the current cache data for this request into a portable hydration payload (useful for SSR).

Preview
dehydrate(config: { override?: boolean; response?: ResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>> })
Parameters
Parameters
NameTypeDescription
config
{ override?: boolean; response?: ResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>> }
Returns
undefined | HydrateDataType<Response, (LocalError | ExtractClientGlobalError<Client>), ExtractClientAdapterType<Client>>

read()

Read the response from cache data

If it returns error and data at the same time, it means that latest request was failed and we show previous data from cache together with error received from actual request

Preview
read()
Returns
undefined | ResponseType<Response, (LocalError | ExtractClientGlobalError<Client>), ExtractClientAdapterType<Client>>

setAbortKey()

Override the abort key used to cancel this request.

Preview
setAbortKey(abortKey: string)
Parameters
Parameters
NameTypeDescription
abortKey
string
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setAuth()

Set whether authentication interceptors should run for this request.

Preview
setAuth(auth: boolean)
Parameters
Parameters
NameTypeDescription
auth
boolean
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setCache()

Set whether this request should use the cache.

Preview
setCache(cache: undefined | boolean)
Parameters
Parameters
NameTypeDescription
cache
undefined | boolean
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setCacheKey()

Override the cache key used to store/retrieve the response.

Preview
setCacheKey(cacheKey: string)
Parameters
Parameters
NameTypeDescription
cacheKey
string
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setCacheTime()

Set how long (in ms) the response remains in cache before being garbage collected.

Preview
setCacheTime(cacheTime: undefined | number)
Parameters
Parameters
NameTypeDescription
cacheTime
undefined | number
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setCancelable()

Set whether in-flight requests with the same abort key are cancelled when a new one is dispatched.

Preview
setCancelable(cancelable: boolean)
Parameters
Parameters
NameTypeDescription
cancelable
boolean
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setDeduplicate()

Enable or disable request deduplication. When enabled, concurrent identical requests share a single response.

Preview
setDeduplicate(deduplicate: boolean)
Parameters
Parameters
NameTypeDescription
deduplicate
boolean
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setDeduplicateTime()

Set the time window (in ms) during which identical requests are deduplicated.

Preview
setDeduplicateTime(deduplicateTime: number)
Parameters
Parameters
NameTypeDescription
deduplicateTime
number
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setHeaders()

Set the request headers. Returns a cloned request with the new headers applied.

Preview
setHeaders(headers: HeadersInit)
Parameters
Parameters
NameTypeDescription
headers
HeadersInit
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setMock()

Attach a mock handler to this request. When mocking is enabled, the handler is called instead of the real adapter.

Preview
setMock(fn: (options: { request: Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, undefined>; requestId: string }) => SyncOrAsync<MockResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>>>, config: MockerConfigType)
Parameters
Parameters
NameTypeDescription
fn
(options: { request: Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, undefined>; requestId: string }) => SyncOrAsync<MockResponseType<Response, LocalError | ExtractClientGlobalError<Client>, ExtractClientAdapterType<Client>>>
config
MockerConfigType
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setMockingEnabled()

Enable or disable the mocker for this request without removing the mock handler.

Preview
setMockingEnabled(isMockerEnabled: boolean)
Parameters
Parameters
NameTypeDescription
isMockerEnabled
boolean
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setOffline()

Set whether the request should be stored in the offline queue when there is no network connection.

Preview
setOffline(offline: boolean)
Parameters
Parameters
NameTypeDescription
offline
boolean
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setOptimistic()

Configure optimistic update behavior for this request. The callback runs before the request is sent (in React's useSubmit ) and receives the request, client, and payload. Return context (available in submit callbacks),

rollback (called automatically on failure/abort), and invalidate (cache keys invalidated on success).

Preview
setOptimistic<Ctx>(callback: OptimisticCallback<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, Ctx>)
Parameters
Parameters
NameTypeDescription
callback
OptimisticCallback<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, Ctx>
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, Ctx>

setOptions()

Set adapter-specific options (e.g., axios config, fetch init).

Preview
setOptions(options: ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>)
Parameters
Parameters
NameTypeDescription
options
ExtractAdapterOptionsType<ExtractClientAdapterType<Client>>
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, true, MutationContext>

setParams()

Set the URL path parameters (e.g., :userId ).

Preview
setParams<P>(params: P)
Parameters
Parameters
NameTypeDescription
params
P
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, P extends null ? false : true, HasQuery, MutationContext>

setPayload()

Set the request body payload.

Preview
setPayload<P>(payload: P)
Parameters
Parameters
NameTypeDescription
payload
P
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, P extends null ? false : true, HasParams, HasQuery, MutationContext>

setPayloadMapper()

Map data before it gets send to the server

Preview
setPayloadMapper<MappedPayload>(payloadMapper: (data: Payload) => MappedPayload)
Parameters
Parameters
NameTypeDescription
payloadMapper
(data: Payload) => MappedPayload
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setQueryKey()

Override the query key that identifies this request in the dispatcher queue.

Preview
setQueryKey(queryKey: string)
Parameters
Parameters
NameTypeDescription
queryKey
string
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setQueryParams()

Set the query parameters appended to the URL.

Preview
setQueryParams(queryParams: QueryParams)
Parameters
Parameters
NameTypeDescription
queryParams
QueryParams
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, true, MutationContext>

setQueued()

Set whether the request should be queued and executed sequentially rather than immediately.

Preview
setQueued(queued: boolean)
Parameters
Parameters
NameTypeDescription
queued
boolean
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setRequestMapper()

Map request before it gets send to the server

Preview
setRequestMapper<NewRequest>(requestMapper: RequestMapper<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, NewRequest>)
Parameters
Parameters
NameTypeDescription
requestMapper
RequestMapper<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, NewRequest>

mapper of the request

Returns
new request
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setResponseMapper()

Map the response to the new interface

Preview
setResponseMapper<MappedResponse>(responseMapper: ResponseMapper<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, MappedResponse>)
Parameters
Parameters
NameTypeDescription
responseMapper
ResponseMapper<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>, MappedResponse>

our mapping callback

Returns
new response
Request<MappedResponse extends ResponseType<R, any, any> ? R : Response, Payload, QueryParams, MappedResponse extends ResponseType<any, E, any> ? E : LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setRetry()

Set the number of retry attempts on failure.

Preview
setRetry(retry: undefined | number)
Parameters
Parameters
NameTypeDescription
retry
undefined | number
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setRetryOnError()

Set a callback that controls whether a failed request should be retried. Called on each failed attempt before scheduling the next retry. Return true to allow the retry, false to stop retrying immediately.

Preview
setRetryOnError(callback: RetryOnErrorCallbackType<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, undefined>>)
Parameters
Parameters
NameTypeDescription
callback
RetryOnErrorCallbackType<Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, undefined>>
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setRetryTime()

Set the delay in milliseconds between retry attempts.

Preview
setRetryTime(retryTime: undefined | number)
Parameters
Parameters
NameTypeDescription
retryTime
undefined | number
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setScope()

Set a scope identifier for this request. All keys (cache, queue, abort) are prefixed with this scope, isolating the request from other scopes. In "server" client mode, setting a scope also enables caching (which is otherwise disabled to prevent cross-request leaks).

Preview
setScope(scopeId: string)
Parameters
Parameters
NameTypeDescription
scopeId
string
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setStaleTime()

Set how long (in ms) cached data is considered fresh before triggering a revalidation.

Preview
setStaleTime(staleTime: undefined | number)
Parameters
Parameters
NameTypeDescription
staleTime
undefined | number
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

setUsed()

Mark the request as used (prevents automatic refetching in hooks).

Preview
setUsed(used: boolean)
Parameters
Parameters
NameTypeDescription
used
boolean
Returns
Request<Response, Payload, QueryParams, LocalError, Endpoint, Client, HasPayload, HasParams, HasQuery, MutationContext>

toJSON()

Serialize the request configuration into a plain JSON object for persistence or transfer.

Preview
toJSON()
Returns
toJSON
NameTypeDescription
abortKey
string
auth
boolean
cache
boolean
cacheKey
string
cacheTime
number
cancelable
boolean
deduplicate
boolean
deduplicateTime
number | null
disableRequestInterceptors
boolean | undefined
disableResponseInterceptors
boolean | undefined
endpoint
ExtractEndpointType<Request>
hasMock
boolean
headers
HeadersInit
isMockerEnabled
boolean
method
ExtractAdapterMethodType<ExtractAdapterType<Request>>
offline
boolean
options
ExtractAdapterOptionsType<ExtractAdapterType<Request>>
params
ExtractParamsType<Request> | EmptyTypes
payload
PayloadType<ExtractPayloadType<Request>>
queryKey
string
queryParams
ExtractQueryParamsType<Request> | EmptyTypes
queued
boolean
requestOptions
RequestOptionsType<ExtractEndpointType<Request>, ExtractAdapterOptionsType<ExtractAdapterType<Request>>, ExtractAdapterMethodType<ExtractAdapterType<Request>>>
retry
number
retryTime
number
scope
string | null
staleTime
number
updatedAbortKey
boolean
updatedCacheKey
boolean
updatedQueryKey
boolean
used
boolean

fromJSON()

Reconstruct a Request instance from a previously serialized JSON representation.

Preview
fromJSON<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery>(client: NewClient, json: RequestJSON<Request<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery, undefined>>)
Parameters
Parameters
NameTypeDescription
client
NewClient
json
RequestJSON<Request<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery, undefined>>
Returns
Request<NewResponse, NewPayload, NewQueryParams, NewLocalError, NewEndpoint, NewClient, NewHasPayload, NewHasParams, NewHasQuery, undefined>