Skip to main content
Version: 3.x.x

Client


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

Description

Client is a class that allows you to configure the connection with the server and then use it to create requests which, when called using the appropriate method, will cause the server to be queried for the endpoint and method specified in the request.

Defined in client/client.ts:40

Parameters

NameDetails

options

Required

ClientOptionsType<Client<GlobalErrorType, AdapterType>>

Properties

adapter

Description

Defined in client/client.ts:60

Type

AdapterType

appManager

Description

Defined in client/client.ts:56

Type

AppManager

cache

Description

Defined in client/client.ts:61

Type

Cache<Client<GlobalErrorType, AdapterType>>

debug

Description

Defined in client/client.ts:45

Type

boolean

defaultAdditionalData

Description

Defined in client/client.ts:66

Type

ExtractAdapterAdditionalDataType<AdapterType>

defaultMethod

Description

Defined in client/client.ts:65

Type

ExtractAdapterMethodType<AdapterType>

effects

Description

Defined in client/client.ts:70

Type

RequestEffectInstance[]

fetchDispatcher

Description

Defined in client/client.ts:62

Type

Dispatcher

logger

Description

Defined in client/client.ts:100

Type

LoggerType

loggerManager

Description

Defined in client/client.ts:57

Type

LoggerManager

options

Description

Defined in client/client.ts:102

Type

ClientOptionsType<Client<GlobalErrorType, AdapterType>>

queryParamsConfig

Description

Defined in client/client.ts:73

Type

QueryStringifyOptionsType

requestManager

Description

Defined in client/client.ts:55

Type

RequestManager

submitDispatcher

Description

Defined in client/client.ts:63

Type

Dispatcher

url

Description

Defined in client/client.ts:44

Type

string

__onAuthCallbacks

Description

Defined in client/client.ts:51

Type

RequestInterceptorType[]

__onErrorCallbacks

Description

Defined in client/client.ts:48

Type

ResponseInterceptorType<any, any, BaseAdapterType<Partial<XMLHttpRequest>, HttpMethodsType, number, AdapterAdditionalDataType, string | QueryParamsType>>[]

__onRequestCallbacks

Description

Defined in client/client.ts:52

Type

RequestInterceptorType[]

__onResponseCallbacks

Description

Defined in client/client.ts:50

Type

ResponseInterceptorType<any, any, BaseAdapterType<Partial<XMLHttpRequest>, HttpMethodsType, number, AdapterAdditionalDataType, string | QueryParamsType>>[]

__onSuccessCallbacks

Description

Defined in client/client.ts:49

Type

ResponseInterceptorType<any, any, BaseAdapterType<Partial<XMLHttpRequest>, HttpMethodsType, number, AdapterAdditionalDataType, string | QueryParamsType>>[]

Methods

abortKeyMapper()

Description

Defined in client/client.ts:78

Return

(request: RequestInstance) => string

adapterDefaultOptions()

Description

Defined in client/client.ts:74

Return

(request: RequestInstance) => ExtractAdapterOptions<AdapterType>

cacheKeyMapper()

Description

Defined in client/client.ts:79

Return

(request: RequestInstance) => string

effectKeyMapper()

Description

Defined in client/client.ts:81

Return

(request: RequestInstance) => string

headerMapper()

Description

Method to get default headers and to map them based on the data format exchange, by default it handles FormData / JSON formats.

Defined in client/client.ts:93

Return

(request: T) => HeadersInit

payloadMapper()

Description

Method to get request data and transform them to the required format. It handles FormData and JSON by default.

Defined in client/client.ts:97

Return

(data: unknown) => string | FormData

queueKeyMapper()

Description

Defined in client/client.ts:80

Return

(request: RequestInstance) => string

requestDefaultOptions()

Description

Defined in client/client.ts:75

Return

(options: RequestOptionsType<string, ExtractAdapterOptions<AdapterType>, ExtractAdapterMethodType<AdapterType>>) => Partial<RequestOptionsType<string, ExtractAdapterOptions<AdapterType>, ExtractAdapterMethodType<AdapterType>>>

stringifyQueryParams()

Description

Method to stringify query params from objects.

Defined in client/client.ts:88

Return

(queryParams: QueryParamsType | string | NegativeTypes) => string

addEffect()

Preview

addEffect(effect)

Description

Add persistent effects which trigger on the request lifecycle

Defined in client/client.ts:265

Parameters

NameDetails

effect

Required

RequestEffectInstance | RequestEffectInstance[]

Return

this

clear()

Preview

clear()

Description

Clears the Client instance and remove all listeners on it's dependencies

Defined in client/client.ts:335

Return

void

createRequest()

Preview

createRequest<Response, Payload, LocalError, QueryParams>()

Description

Create requests based on the Client setup

Defined in client/client.ts:357

Return

(params: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Request<Response, Payload, QueryParams, GlobalErrorType, LocalError, EndpointType, ExtractUnionAdapter<AdapterType, [object Object]>, false, false, false>

onAuth()

Preview

onAuth(callback)

Description

Method of manipulating requests before sending the request. We can for example add custom header with token to the request which request had the auth set to true.

Defined in client/client.ts:219

Parameters

NameDetails

callback

Required

RequestInterceptorType

Return

Client<GlobalErrorType, AdapterType>

onError()

Preview

onError<ErrorType>(callback)

Description

Method for intercepting error responses. It can be used for example to refresh tokens.

Defined in client/client.ts:227

Parameters

NameDetails

callback

Required

ResponseInterceptorType<any, GlobalErrorType | ErrorType, AdapterType>

Return

Client<GlobalErrorType, AdapterType>

onRequest()

Preview

onRequest(callback)

Description

Method of manipulating requests before sending the request.

Defined in client/client.ts:247

Parameters

NameDetails

callback

Required

RequestInterceptorType

Return

Client<GlobalErrorType, AdapterType>

onResponse()

Preview

onResponse<ErrorType>(callback)

Description

Method for intercepting any responses.

Defined in client/client.ts:255

Parameters

NameDetails

callback

Required

ResponseInterceptorType<any, GlobalErrorType | ErrorType, AdapterType>

Return

Client<GlobalErrorType, AdapterType>

onSuccess()

Preview

onSuccess<ErrorType>(callback)

Description

Method for intercepting success responses.

Defined in client/client.ts:237

Parameters

NameDetails

callback

Required

ResponseInterceptorType<any, GlobalErrorType | ErrorType, AdapterType>

Return

Client<GlobalErrorType, AdapterType>

removeEffect()

Preview

removeEffect(effect)

Description

Remove effects from Client

Defined in client/client.ts:274

Parameters

NameDetails

effect

Required

string | RequestEffectInstance

Return

this

setAbortKeyMapper()

Preview

setAbortKeyMapper(callback)

Description

Key setters

Defined in client/client.ts:285

Parameters

NameDetails

callback

Required

(request: RequestInstance) => string

Return

void

setAdapter()

Preview

setAdapter<NewAdapterType>(callback)

Description

Set custom http adapter to handle graphql, rest, firebase or others

Defined in client/client.ts:193

Parameters

NameDetails

callback

Required

(Client: ClientInstance) => NewAdapterType

Return

Client<GlobalErrorType, NewAdapterType>

setAdapterDefaultOptions()

Preview

setAdapterDefaultOptions(callback)

Description

Defined in client/client.ts:126

Parameters

NameDetails

callback

Required

(request: RequestInstance) => ExtractAdapterOptions<AdapterType>

Return

Client<GlobalErrorType, AdapterType>

setCacheKeyMapper()

Preview

setCacheKeyMapper(callback)

Description

Defined in client/client.ts:288

Parameters

NameDetails

callback

Required

(request: RequestInstance) => string

Return

void

setDebug()

Preview

setDebug(debug)

Description

This method enables the logger usage and display the logs in console

Defined in client/client.ts:136

Parameters

NameDetails

debug

Required

boolean

Return

Client<GlobalErrorType, AdapterType>

setDefaultAdditionalData()

Preview

setDefaultAdditionalData(defaultAdditionalData)

Description

Set default additional data for initial state.

Defined in client/client.ts:211

Parameters

NameDetails

defaultAdditionalData

Required

ExtractAdapterAdditionalDataType<AdapterType>

Return

Client<any, BaseAdapterType<any, any, any, any>>

setDefaultMethod()

Preview

setDefaultMethod(defaultMethod)

Description

Set default method for requests.

Defined in client/client.ts:203

Parameters

NameDetails

defaultMethod

Required

ExtractAdapterMethodType<AdapterType>

Return

Client<any, BaseAdapterType<any, any, any, any>>

setEffectKeyMapper()

Preview

setEffectKeyMapper(callback)

Description

Defined in client/client.ts:294

Parameters

NameDetails

callback

Required

(request: RequestInstance) => string

Return

void

setHeaderMapper()

Preview

setHeaderMapper(headerMapper)

Description

Set the custom header mapping function

Defined in client/client.ts:177

Parameters

NameDetails

headerMapper

Required

HeaderMappingType

Return

Client<GlobalErrorType, AdapterType>

setLogger()

Preview

setLogger(callback)

Description

Set the new logger instance to the Client

Defined in client/client.ts:152

Parameters

NameDetails

callback

Required

(Client: ClientInstance) => LoggerManager

Return

Client<GlobalErrorType, AdapterType>

setLoggerSeverity()

Preview

setLoggerSeverity(severity)

Description

Set the logger severity of the messages displayed to the console

Defined in client/client.ts:144

Parameters

NameDetails

severity

Required

SeverityType

Return

Client<GlobalErrorType, AdapterType>

setPayloadMapper()

Preview

setPayloadMapper(payloadMapper)

Description

Set the request payload mapping function which get triggered before request get send

Defined in client/client.ts:185

Parameters

NameDetails

payloadMapper

Required

AdapterPayloadMappingType

Return

Client<GlobalErrorType, AdapterType>

setQueryParamsConfig()

Preview

setQueryParamsConfig(queryParamsConfig)

Description

Set config for the query params stringify method, we can set here, among others, arrayFormat, skipNull, encode, skipEmptyString and more

Defined in client/client.ts:160

Parameters

NameDetails

queryParamsConfig

Required

QueryStringifyOptionsType

Return

Client<GlobalErrorType, AdapterType>

setQueueKeyMapper()

Preview

setQueueKeyMapper(callback)

Description

Defined in client/client.ts:291

Parameters

NameDetails

callback

Required

(request: RequestInstance) => string

Return

void

setRequestDefaultOptions()

Preview

setRequestDefaultOptions(callback)

Description

This method allows to configure global defaults for the request configuration like method, auth, deduplication etc.

Defined in client/client.ts:117

Parameters

NameDetails

callback

Required

(request: RequestInstance) => Partial<RequestOptionsType<string, ExtractAdapterOptions<AdapterType>, ExtractAdapterMethodType<AdapterType>>>

Return

Client<GlobalErrorType, AdapterType>

setStringifyQueryParams()

Preview

setStringifyQueryParams(stringifyFn)

Description

Set the custom query params stringify method to the Client

Defined in client/client.ts:169

Parameters

NameDetails

stringifyFn

Required

Custom callback handling query params stringify

StringifyCallbackType

Return

Client<GlobalErrorType, AdapterType>

__modifyAuth()

Preview

__modifyAuth(request)

Description

Helper used by http adapter to apply the modifications on response error

Defined in client/client.ts:301

Parameters

NameDetails

request

Required

RequestInstance

Return

Promise<RequestInstance>

__modifyErrorResponse()

Preview

__modifyErrorResponse(response, request)

Description

Private helper to run async on-error response processing

Defined in client/client.ts:311

Parameters

NameDetails

response

Required

ResponseReturnType<any, GlobalErrorType, AdapterType>

request

Required

RequestInstance

Return

Promise<ResponseReturnType<any, GlobalErrorType, AdapterType>>

__modifyRequest()

Preview

__modifyRequest(request)

Description

Private helper to run async pre-request processing

Defined in client/client.ts:306

Parameters

NameDetails

request

Required

RequestInstance

Return

Promise<RequestInstance>

__modifyResponse()

Preview

__modifyResponse(response, request)

Description

Private helper to run async response processing

Defined in client/client.ts:327

Parameters

NameDetails

response

Required

ResponseReturnType<any, GlobalErrorType, AdapterType>

request

Required

RequestInstance

Return

Promise<ResponseReturnType<any, GlobalErrorType, AdapterType>>

__modifySuccessResponse()

Preview

__modifySuccessResponse(response, request)

Description

Private helper to run async on-success response processing

Defined in client/client.ts:319

Parameters

NameDetails

response

Required

ResponseReturnType<any, GlobalErrorType, AdapterType>

request

Required

RequestInstance

Return

Promise<ResponseReturnType<any, GlobalErrorType, AdapterType>>