Skip to main content
Version: Current

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:35

Parameters

NameDetails

options

Required

ClientOptionsType

Properties

appManager

Description

Defined in client/client.ts:48

Type

AppManager

cache

Description

Defined in client/client.ts:53

Type

Cache

debug

Description

Defined in client/client.ts:37

Type

boolean

effects

Description

Defined in client/client.ts:58

Type

RequestEffectInstance[]

fetchDispatcher

Description

Defined in client/client.ts:54

Type

Dispatcher

logger

Description

Defined in client/client.ts:84

Type

LoggerType

loggerManager

Description

Defined in client/client.ts:49

Type

LoggerManager

options

Description

Defined in client/client.ts:86

Type

ClientOptionsType

queryParamsConfig

Description

Defined in client/client.ts:61

Type

QueryStringifyOptionsType

requestManager

Description

Defined in client/client.ts:47

Type

RequestManager

submitDispatcher

Description

Defined in client/client.ts:55

Type

Dispatcher

url

Description

Defined in client/client.ts:36

Type

string

__onAuthCallbacks

Description

Defined in client/client.ts:43

Type

RequestInterceptorType[]

__onErrorCallbacks

Description

Defined in client/client.ts:40

Type

ResponseInterceptorType<any, any>[]

__onRequestCallbacks

Description

Defined in client/client.ts:44

Type

RequestInterceptorType[]

__onResponseCallbacks

Description

Defined in client/client.ts:42

Type

ResponseInterceptorType<any, any>[]

__onSuccessCallbacks

Description

Defined in client/client.ts:41

Type

ResponseInterceptorType<any, any>[]

Methods

adapter()

Description

Defined in client/client.ts:52

Return

(request: RequestInstance, requestId: string) => Promise<ResponseType<any, any>>

adapterDefaultOptions()

Description

Defined in client/client.ts:62

Return

(request: RequestInstance) => AdapterOptions

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:77

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:81

Return

(data: unknown) => string | FormData

requestDefaultOptions()

Description

Defined in client/client.ts:63

Return

(options: RequestOptionsType<string, AdapterOptions>) => Partial<RequestOptionsType<string, AdapterOptions>>

stringifyQueryParams()

Description

Method to stringify query params from objects.

Defined in client/client.ts:72

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:229

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:276

Return

void

createRequest()

Preview

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

Description

Create requests based on the Client setup

Defined in client/client.ts:298

Return

(params: RequestOptionsType<EndpointType, AdapterOptions>) => Request<Response, Payload, QueryParams, GlobalErrorType, LocalError, EndpointType, AdapterOptions, false, false, false, undefined>

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:183

Parameters

NameDetails

callback

Required

RequestInterceptorType

Return

Client<GlobalErrorType, AdapterOptions>

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:191

Parameters

NameDetails

callback

Required

ResponseInterceptorType<any, GlobalErrorType | ErrorType>

Return

Client<GlobalErrorType, AdapterOptions>

onRequest()

Preview

onRequest(callback)

Description

Method of manipulating requests before sending the request.

Defined in client/client.ts:211

Parameters

NameDetails

callback

Required

RequestInterceptorType

Return

Client<GlobalErrorType, AdapterOptions>

onResponse()

Preview

onResponse<ErrorType>(callback)

Description

Method for intercepting any responses.

Defined in client/client.ts:219

Parameters

NameDetails

callback

Required

ResponseInterceptorType<any, GlobalErrorType | ErrorType>

Return

Client<GlobalErrorType, AdapterOptions>

onSuccess()

Preview

onSuccess<ErrorType>(callback)

Description

Method for intercepting success responses.

Defined in client/client.ts:201

Parameters

NameDetails

callback

Required

ResponseInterceptorType<any, GlobalErrorType | ErrorType>

Return

Client<GlobalErrorType, AdapterOptions>

removeEffect()

Preview

removeEffect(effect)

Description

Remove effects from Client

Defined in client/client.ts:238

Parameters

NameDetails

effect

Required

string | RequestEffectInstance

Return

this

setAdapter()

Preview

setAdapter(callback)

Description

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

Defined in client/client.ts:175

Parameters

NameDetails

callback

Required

(Client: ClientInstance) => AdapterType

Return

Client<GlobalErrorType, AdapterOptions>

setAdapterDefaultOptions()

Preview

setAdapterDefaultOptions(callback)

Description

Defined in client/client.ts:108

Parameters

NameDetails

callback

Required

(request: RequestInstance) => AdapterOptions

Return

Client<GlobalErrorType, AdapterOptions>

setDebug()

Preview

setDebug(debug)

Description

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

Defined in client/client.ts:118

Parameters

NameDetails

debug

Required

boolean

Return

Client<GlobalErrorType, AdapterOptions>

setHeaderMapper()

Preview

setHeaderMapper(headerMapper)

Description

Set the custom header mapping function

Defined in client/client.ts:159

Parameters

NameDetails

headerMapper

Required

HeaderMappingType

Return

Client<GlobalErrorType, AdapterOptions>

setLogger()

Preview

setLogger(callback)

Description

Set the new logger instance to the Client

Defined in client/client.ts:134

Parameters

NameDetails

callback

Required

(Client: ClientInstance) => LoggerManager

Return

Client<GlobalErrorType, AdapterOptions>

setLoggerSeverity()

Preview

setLoggerSeverity(severity)

Description

Set the logger severity of the messages displayed to the console

Defined in client/client.ts:126

Parameters

NameDetails

severity

Required

SeverityType

Return

Client<GlobalErrorType, AdapterOptions>

setPayloadMapper()

Preview

setPayloadMapper(payloadMapper)

Description

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

Defined in client/client.ts:167

Parameters

NameDetails

payloadMapper

Required

AdapterPayloadMappingType

Return

Client<GlobalErrorType, AdapterOptions>

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:142

Parameters

NameDetails

queryParamsConfig

Required

QueryStringifyOptionsType

Return

Client<GlobalErrorType, AdapterOptions>

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:101

Parameters

NameDetails

callback

Required

(request: RequestInstance) => Partial<RequestOptionsType<string, AdapterOptions>>

Return

Client<GlobalErrorType, AdapterOptions>

setStringifyQueryParams()

Preview

setStringifyQueryParams(stringifyFn)

Description

Set the custom query params stringify method to the Client

Defined in client/client.ts:151

Parameters

NameDetails

stringifyFn

Required

Custom callback handling query params stringify

StringifyCallbackType

Return

Client<GlobalErrorType, AdapterOptions>

__modifyAuth()

Preview

__modifyAuth(request)

Description

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

Defined in client/client.ts:248

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:258

Parameters

NameDetails

response

Required

ResponseType<any, GlobalErrorType>

request

Required

RequestInstance

Return

Promise<ResponseType<any, GlobalErrorType>>

__modifyRequest()

Preview

__modifyRequest(request)

Description

Private helper to run async pre-request processing

Defined in client/client.ts:253

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:270

Parameters

NameDetails

response

Required

ResponseType<any, GlobalErrorType>

request

Required

RequestInstance

Return

Promise<ResponseType<any, GlobalErrorType>>

__modifySuccessResponse()

Preview

__modifySuccessResponse(response, request)

Description

Private helper to run async on-success response processing

Defined in client/client.ts:264

Parameters

NameDetails

response

Required

ResponseType<any, GlobalErrorType>

request

Required

RequestInstance

Return

Promise<ResponseType<any, GlobalErrorType>>