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
Name | Details |
---|---|
options
|
|
Properties
options
options
Description
Defined in client/client.ts:98
Type
ClientOptionsType<Client<GlobalErrorType, Adapter>>
__onErrorCallbacks
__onErrorCallbacks
Description
Defined in client/client.ts:45
Type
ResponseInterceptorType<any, any, AdapterType<Partial<XMLHttpRequest>, HttpMethodsType, number, AdapterExtraType, string | QueryParamsType>>[]
__onResponseCallbacks
__onResponseCallbacks
Description
Defined in client/client.ts:47
Type
ResponseInterceptorType<any, any, AdapterType<Partial<XMLHttpRequest>, HttpMethodsType, number, AdapterExtraType, string | QueryParamsType>>[]
__onSuccessCallbacks
__onSuccessCallbacks
Description
Defined in client/client.ts:46
Type
ResponseInterceptorType<any, any, AdapterType<Partial<XMLHttpRequest>, HttpMethodsType, number, AdapterExtraType, string | QueryParamsType>>[]
Methods
abortKeyMapper()
abortKeyMapper()
Description
Defined in client/client.ts:74
Return
(request: RequestInstance) => string
adapterDefaultOptions()
adapterDefaultOptions()
Description
Defined in client/client.ts:70
Return
(request: RequestInstance) => ExtractAdapterOptionsType<Adapter>
cacheKeyMapper()
cacheKeyMapper()
Description
Defined in client/client.ts:75
Return
(request: RequestInstance) => string
effectKeyMapper()
effectKeyMapper()
Description
Defined in client/client.ts:77
Return
(request: RequestInstance) => string
headerMapper()
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:89
Return
(request: T) => HeadersInit
payloadMapper()
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:93
Return
(data: unknown) => string | FormData
queueKeyMapper()
queueKeyMapper()
Description
Defined in client/client.ts:76
Return
(request: RequestInstance) => string
requestDefaultOptions()
requestDefaultOptions()
Description
Defined in client/client.ts:71
Return
(options: RequestOptionsType<string, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>) => Partial<RequestOptionsType<string, ExtractAdapterOptionsType<Adapter>, ExtractAdapterMethodType<Adapter>>>
stringifyQueryParams()
stringifyQueryParams()
Description
Method to stringify query params from objects.
Defined in client/client.ts:84
Return
(queryParams: QueryParamsType | string | NegativeTypes) => string
addEffect()
addEffect()
Preview
addEffect(effect)
Description
Add persistent effects which trigger on the request lifecycle
Defined in client/client.ts:261
Parameters
Name | Details |
---|---|
effect
|
|
Return
this
clear()
clear()
Preview
clear()
Description
Clears the Client instance and remove all listeners on it's dependencies
Defined in client/client.ts:329
Return
void
createRequest()
createRequest()
Preview
createRequest<Response, Payload, LocalError, QueryParams>()
Description
Create requests based on the Client setup
Defined in client/client.ts:351
Return
(params: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Request<Response, Payload, QueryParams, GlobalErrorType, LocalError, EndpointType, ExtractUnionAdapter<Adapter, [object Object]>, false, false, false>
onAuth()
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:215
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, Adapter>
onError()
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:223
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, Adapter>
onRequest()
onRequest()
Preview
onRequest(callback)
Description
Method of manipulating requests before sending the request.
Defined in client/client.ts:243
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, Adapter>
onResponse()
onResponse()
Preview
onResponse<ErrorType>(callback)
Description
Method for intercepting any responses.
Defined in client/client.ts:251
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, Adapter>
onSuccess()
onSuccess()
Preview
onSuccess<ErrorType>(callback)
Description
Method for intercepting success responses.
Defined in client/client.ts:233
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, Adapter>
removeEffect()
removeEffect()
Preview
removeEffect(effect)
Description
Remove effects from Client
Defined in client/client.ts:270
Parameters
Name | Details |
---|---|
effect
|
|
Return
this
setAbortKeyMapper()
setAbortKeyMapper()
Preview
setAbortKeyMapper(callback)
Description
Key setters
Defined in client/client.ts:281
Parameters
Name | Details |
---|---|
callback
|
|
Return
void
setAdapter()
setAdapter()
Preview
setAdapter<NewAdapter>(callback)
Description
Set custom http adapter to handle graphql, rest, firebase or others
Defined in client/client.ts:189
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, NewAdapter>
setAdapterDefaultOptions()
setAdapterDefaultOptions()
Preview
setAdapterDefaultOptions(callback)
Description
Defined in client/client.ts:122
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, Adapter>
setCacheKeyMapper()
setCacheKeyMapper()
Preview
setCacheKeyMapper(callback)
Description
Defined in client/client.ts:284
Parameters
Name | Details |
---|---|
callback
|
|
Return
void
setDebug()
setDebug()
Preview
setDebug(debug)
Description
This method enables the logger usage and display the logs in console
Defined in client/client.ts:132
Parameters
Name | Details |
---|---|
debug
|
|
Return
Client<GlobalErrorType, Adapter>
setDefaultExtra()
setDefaultExtra()
Preview
setDefaultExtra(defaultExtra)
Description
Set default additional data for initial state.
Defined in client/client.ts:207
Parameters
Name | Details |
---|---|
defaultExtra
|
|
Return
Client<any, AdapterType<any, any, any, any>>
setDefaultMethod()
setDefaultMethod()
Preview
setDefaultMethod(defaultMethod)
Description
Set default method for requests.
Defined in client/client.ts:199
Parameters
Name | Details |
---|---|
defaultMethod
|
|
Return
Client<any, AdapterType<any, any, any, any>>
setEffectKeyMapper()
setEffectKeyMapper()
Preview
setEffectKeyMapper(callback)
Description
Defined in client/client.ts:290
Parameters
Name | Details |
---|---|
callback
|
|
Return
void
setHeaderMapper()
setHeaderMapper()
Preview
setHeaderMapper(headerMapper)
Description
Set the custom header mapping function
Defined in client/client.ts:173
Parameters
Name | Details |
---|---|
headerMapper
|
|
Return
Client<GlobalErrorType, Adapter>
setLogger()
setLogger()
Preview
setLogger(callback)
Description
Set the new logger instance to the Client
Defined in client/client.ts:148
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, Adapter>
setLoggerSeverity()
setLoggerSeverity()
Preview
setLoggerSeverity(severity)
Description
Set the logger severity of the messages displayed to the console
Defined in client/client.ts:140
Parameters
Name | Details |
---|---|
severity
|
|
Return
Client<GlobalErrorType, Adapter>
setPayloadMapper()
setPayloadMapper()
Preview
setPayloadMapper(payloadMapper)
Description
Set the request payload mapping function which get triggered before request get send
Defined in client/client.ts:181
Parameters
Name | Details |
---|---|
payloadMapper
|
|
Return
Client<GlobalErrorType, Adapter>
setQueryParamsConfig()
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:156
Parameters
Name | Details |
---|---|
queryParamsConfig
|
|
Return
Client<GlobalErrorType, Adapter>
setQueueKeyMapper()
setQueueKeyMapper()
Preview
setQueueKeyMapper(callback)
Description
Defined in client/client.ts:287
Parameters
Name | Details |
---|---|
callback
|
|
Return
void
setRequestDefaultOptions()
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:113
Parameters
Name | Details |
---|---|
callback
|
|
Return
Client<GlobalErrorType, Adapter>
setStringifyQueryParams()
setStringifyQueryParams()
Preview
setStringifyQueryParams(stringifyFn)
Description
Set the custom query params stringify method to the Client
Defined in client/client.ts:165
Parameters
Name | Details |
---|---|
stringifyFn
| Custom callback handling query params stringify
|
Return
Client<GlobalErrorType, Adapter>
__modifyAuth()
__modifyAuth()
Preview
__modifyAuth(request)
Description
Helper used by http adapter to apply the modifications on response error
Defined in client/client.ts:297
Parameters
Name | Details |
---|---|
request
|
|
Return
Promise<RequestInstance>
__modifyErrorResponse()
__modifyErrorResponse()
Preview
__modifyErrorResponse(response, request)
Description
Private helper to run async on-error response processing
Defined in client/client.ts:307
Parameters
Name | Details |
---|---|
response
|
|
request
|
|
Return
Promise<ResponseReturnType<any, GlobalErrorType, Adapter>>
__modifyRequest()
__modifyRequest()
Preview
__modifyRequest(request)
Description
Private helper to run async pre-request processing
Defined in client/client.ts:302
Parameters
Name | Details |
---|---|
request
|
|
Return
Promise<RequestInstance>
__modifyResponse()
__modifyResponse()
Preview
__modifyResponse(response, request)
Description
Private helper to run async response processing
Defined in client/client.ts:323
Parameters
Name | Details |
---|---|
response
|
|
request
|
|
Return
Promise<ResponseReturnType<any, GlobalErrorType, Adapter>>
__modifySuccessResponse()
__modifySuccessResponse()
Preview
__modifySuccessResponse(response, request)
Description
Private helper to run async on-success response processing
Defined in client/client.ts:315
Parameters
Name | Details |
---|---|
response
|
|
request
|
|
Return
Promise<ResponseReturnType<any, GlobalErrorType, Adapter>>