Skip to main content
Version: 5.x.x

Request


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

Description

Fetch request it is designed to prepare the necessary setup to execute the request to the server. We can set up basic options for example endpoint, method, headers and advanced settings like cache, invalidation patterns, concurrency, retries and much, much more.

Usage

We should not use this class directly in the standard development flow. We can initialize it using the createRequest method on the Client class.

Defined in request/request.ts:40

Parameters

NameDetails

client

Required

Client<GlobalError, Adapter, DefaultEndpointMapper>

requestOptions

Required

RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>

requestJSON

Optional

RequestCurrentType<Payload, QueryParams, Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>

Properties

abortKey

Description

Defined in request/request.ts:68

Type

string

auth

Description

Defined in request/request.ts:54

Type

boolean

cache

Description

Defined in request/request.ts:64

Type

boolean

cacheKey

Description

Defined in request/request.ts:69

Type

string

cacheTime

Description

Defined in request/request.ts:65

Type

number

cancelable

Description

Defined in request/request.ts:60

Type

boolean

client

Description

Defined in request/request.ts:92

Type

Client<GlobalError, Adapter, DefaultEndpointMapper>

data

Description

Defined in request/request.ts:57

Type

Payload

deduplicate

Description

Defined in request/request.ts:73

Type

boolean

deduplicateTime

Description

Defined in request/request.ts:74

Type

number

effectKey

Description

Defined in request/request.ts:71

Type

string

endpoint

Description

Defined in request/request.ts:52

Type

Endpoint

garbageCollection

Description

Defined in request/request.ts:63

Type

number

headers

Description

Defined in request/request.ts:53

Type

HeadersInit

isMockEnabled

Description

Defined in request/request.ts:82

Type

boolean

method

Description

Defined in request/request.ts:55

Type

ExtractAdapterMethodType<Adapter>

mock

Description

Defined in request/request.ts:76

Type

Generator<GeneratorReturnMockTypes<Response, Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>>, GeneratorReturnMockTypes<Response, Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>>, GeneratorReturnMockTypes<Response, Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>>>

mockData

Description

Defined in request/request.ts:81

Type

RequestDataMockTypes<Response, Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>>

offline

Description

Defined in request/request.ts:67

Type

boolean

options

Description

Defined in request/request.ts:59

Type

ExtractAdapterOptionsType<Adapter>

params

Description

Defined in request/request.ts:56

Type

ExtractRouteParams<Endpoint>

queryParams

Description

Defined in request/request.ts:58

Type

QueryParams

queueKey

Description

Defined in request/request.ts:70

Type

string

queued

Description

Defined in request/request.ts:66

Type

boolean

requestJSON

Description

Defined in request/request.ts:98

Type

RequestCurrentType<Payload, QueryParams, Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>

requestOptions

Description

Defined in request/request.ts:93

Type

RequestOptionsType<Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>

retry

Description

Defined in request/request.ts:61

Type

number

retryTime

Description

Defined in request/request.ts:62

Type

number

used

Description

Defined in request/request.ts:72

Type

boolean

Methods

dataMapper()

Description

Defined in request/request.ts:75

Return

(data: Payload) => NewDataType

exec()

Description

Method to use the request WITHOUT adding it to cache and queues. This mean it will make simple request without queue side effects.

Defined in request/request.ts:471

Return


requestMapper()

Description

Defined in request/request.ts:83

Return

(request: Request, requestId: string) => NewRequest | Promise<NewRequest>

responseMapper()

Description

Defined in request/request.ts:84

Return

(response: ResponseReturnType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>>) => ResponseReturnType<NewResponse, NewError, ExtractAdapterType<Request>> | Promise<ResponseReturnType<NewResponse, NewError, ExtractAdapterType<Request>>>

send()

Description

Method used to perform requests with usage of cache and queues

Defined in request/request.ts:502

Return


abort()

Preview

abort()

Description

Defined in request/request.ts:455

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

clone()

Preview

clone<D, P, Q>(options)

Description

Defined in request/request.ts:409

Parameters

NameDetails

options

Optional

RequestCurrentType<Payload, QueryParams, Endpoint, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, D, P, Q>

removeMock()

Preview

removeMock()

Description

Defined in request/request.ts:293

Return

this

setAbortKey()

Preview

setAbortKey(abortKey)

Description

Defined in request/request.ts:236

Parameters

NameDetails

abortKey

Required

string

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setAuth()

Preview

setAuth(auth)

Description

Defined in request/request.ts:164

Parameters

NameDetails

auth

Required

boolean

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setCache()

Preview

setCache(cache)

Description

Defined in request/request.ts:216

Parameters

NameDetails

cache

Required

boolean

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setCacheKey()

Preview

setCacheKey(cacheKey)

Description

Defined in request/request.ts:241

Parameters

NameDetails

cacheKey

Required

string

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setCacheTime()

Preview

setCacheTime(cacheTime)

Description

Defined in request/request.ts:222

Parameters

NameDetails

cacheTime

Required

number

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setCancelable()

Preview

setCancelable(cancelable)

Description

Defined in request/request.ts:186

Parameters

NameDetails

cancelable

Required

boolean

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setData()

Preview

setData<D>(data)

Description

Defined in request/request.ts:172

Parameters

NameDetails

data

Required

D

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, D extends null ? false : true, HasParams, HasQuery>

setDataMapper()

Preview

setDataMapper<DataMapper>(dataMapper)

Description

Map data before it gets send to the server

Defined in request/request.ts:314

Parameters

NameDetails

dataMapper

Required

DataMapper

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setDeduplicate()

Preview

setDeduplicate(deduplicate)

Description

Defined in request/request.ts:256

Parameters

NameDetails

deduplicate

Required

boolean

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setDeduplicateTime()

Preview

setDeduplicateTime(deduplicateTime)

Description

Defined in request/request.ts:260

Parameters

NameDetails

deduplicateTime

Required

number

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setEffectKey()

Preview

setEffectKey(effectKey)

Description

Defined in request/request.ts:251

Parameters

NameDetails

effectKey

Required

string

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setEnableMocking()

Preview

setEnableMocking(isMockEnabled)

Description

Defined in request/request.ts:300

Parameters

NameDetails

isMockEnabled

Required

boolean

Return

this

setGarbageCollection()

Preview

setGarbageCollection(garbageCollection)

Description

Defined in request/request.ts:206

Parameters

NameDetails

garbageCollection

Required

number

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setHeaders()

Preview

setHeaders(headers)

Description

Defined in request/request.ts:160

Parameters

NameDetails

headers

Required

HeadersInit

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setMock()

Preview

setMock(mockData)

Description

Defined in request/request.ts:272

Parameters

NameDetails

mockData

Required

RequestDataMockTypes<Response, this>

Return

this

setOffline()

Preview

setOffline(offline)

Description

Defined in request/request.ts:268

Parameters

NameDetails

offline

Required

boolean

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setOptions()

Preview

setOptions(options)

Description

Defined in request/request.ts:182

Parameters

NameDetails

options

Required

ExtractAdapterOptionsType<Adapter>

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, true>

setParams()

Preview

setParams<P>(params)

Description

Defined in request/request.ts:168

Parameters

NameDetails

params

Required

P

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, P extends null ? false : true, HasQuery>

setQueryParams()

Preview

setQueryParams(queryParams)

Description

Defined in request/request.ts:178

Parameters

NameDetails

queryParams

Required

QueryParams

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, true>

setQueueKey()

Preview

setQueueKey(queueKey)

Description

Defined in request/request.ts:246

Parameters

NameDetails

queueKey

Required

string

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setQueued()

Preview

setQueued(queued)

Description

Defined in request/request.ts:232

Parameters

NameDetails

queued

Required

boolean

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setRequestMapper()

Preview

setRequestMapper<NewRequest>(requestMapper)

Description

Map request before it gets send to the server

Defined in request/request.ts:327

Parameters

NameDetails

requestMapper

Required

mapper of the request

RequestMapper<this, NewRequest>

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setResponseMapper()

Preview

setResponseMapper<NewResponse, NewError>(responseMapper)

Description

Map the response to the new interface

Defined in request/request.ts:340

Parameters

NameDetails

responseMapper

Optional

our mapping callback

ResponseMapper<this, NewResponse, NewError>

Return

Request<NewResponse, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setRetry()

Preview

setRetry(retry)

Description

Defined in request/request.ts:190

Parameters

NameDetails

retry

Required

number

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setRetryTime()

Preview

setRetryTime(retryTime)

Description

Defined in request/request.ts:196

Parameters

NameDetails

retryTime

Required

number

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

setUsed()

Preview

setUsed(used)

Description

Defined in request/request.ts:264

Parameters

NameDetails

used

Required

boolean

Return

Request<Response, Payload, QueryParams, GlobalError, LocalError, Endpoint, Adapter, HasData, HasParams, HasQuery>

toJSON()

Preview

toJSON()

Description

Defined in request/request.ts:374

Return

{
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
data: Payload | null | undefined;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean | undefined;
disableResponseInterceptors: boolean | undefined;
effectKey: string;
endpoint: string;
garbageCollection: number;
headers: HeadersInit;
method: T extends AdapterType<any, infer M, any, any, any> ? M : never;
offline: boolean;
options: AdapterOptions | T extends AdapterType<infer O, any, any, any, any> ? O : never;
params: Params | null | undefined;
queryParams: QueryParams | null | undefined;
queueKey: string;
queued: boolean;
requestOptions: {
abortKey: string;
auth: boolean;
cache: boolean;
cacheKey: string;
cacheTime: number;
cancelable: boolean;
deduplicate: boolean;
deduplicateTime: number;
disableRequestInterceptors: boolean;
disableResponseInterceptors: boolean;
effectKey: string;
endpoint: GenericEndpoint;
garbageCollection: number;
headers: HeadersInit;
method: RequestMethods;
offline: boolean;
options: AdapterOptions;
queueKey: string;
queued: boolean;
retry: number;
retryTime: number;
};
retry: number;
retryTime: number;
updatedAbortKey: boolean;
updatedCacheKey: boolean;
updatedEffectKey: boolean;
updatedQueueKey: boolean;
used: boolean;
}