Builder
import { Builder } from "@hyper-fetch/core"
Description
Builder is a class that allows you to configure the connection with the server and then use it to create commands which, when called using the appropriate method, will cause the server to be queried for the endpoint and method specified in the command.
Defined in builder/builder.ts:35
Parameters
Name | Details |
---|---|
options
|
|
Properties
__onErrorCallbacks
__onErrorCallbacks
Description
Defined in builder/builder.ts:40
Type
ResponseInterceptorCallback<any, any>[]
__onResponseCallbacks
__onResponseCallbacks
Description
Defined in builder/builder.ts:42
Type
ResponseInterceptorCallback<any, any>[]
__onSuccessCallbacks
__onSuccessCallbacks
Description
Defined in builder/builder.ts:41
Type
ResponseInterceptorCallback<any, any>[]
Methods
client()
client()
Description
Defined in builder/builder.ts:52
Return
(command: CommandInstance, requestId: string) => Promise<ClientResponseType<any, any>>
commandConfig()
commandConfig()
Description
Defined in builder/builder.ts:62
Return
(commandOptions: CommandConfig<string, RequestConfigType>) => Partial<CommandConfig<string, RequestConfigType>>
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 builder/builder.ts:77
Return
(command: 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 builder/builder.ts:81
Return
(data: unknown) => string | FormData
requestConfig()
requestConfig()
Description
Defined in builder/builder.ts:61
Return
(command: CommandInstance) => RequestConfigType
stringifyQueryParams()
stringifyQueryParams()
Description
Method to stringify query params from objects.
Defined in builder/builder.ts:72
Return
(queryParams: ClientQueryParamsType | string | NegativeTypes) => string
addEffect()
addEffect()
Preview
addEffect(effect)
Description
Add persistent effects which trigger on the request lifecycle
Defined in builder/builder.ts:222
Parameters
Name | Details |
---|---|
effect
|
|
Return
this
clear()
clear()
Preview
clear()
Description
Clears the builder instance and remove all listeners on it's dependencies
Defined in builder/builder.ts:269
Return
void
createCommand()
createCommand()
Preview
createCommand<ResponseType, RequestDataType, LocalErrorType, QueryParamsType>()
Description
Create commands based on the builder setup
Defined in builder/builder.ts:291
Return
(params: CommandConfig<EndpointType, RequestConfigType>) => Command<ResponseType, RequestDataType, QueryParamsType, GlobalErrorType, LocalErrorType, EndpointType, RequestConfigType, false, false, false, undefined>
onAuth()
onAuth()
Preview
onAuth(callback)
Description
Method of manipulating commands before sending the request. We can for example add custom header with token to the request which command had the auth set to true.
Defined in builder/builder.ts:176
Parameters
Name | Details |
---|---|
callback
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
onError()
onError()
Preview
onError<ErrorType>(callback)
Description
Method for intercepting error responses. It can be used for example to refresh tokens.
Defined in builder/builder.ts:184
Parameters
Name | Details |
---|---|
callback
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
onRequest()
onRequest()
Preview
onRequest(callback)
Description
Method of manipulating commands before sending the request.
Defined in builder/builder.ts:204
Parameters
Name | Details |
---|---|
callback
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
onResponse()
onResponse()
Preview
onResponse<ErrorType>(callback)
Description
Method for intercepting any responses.
Defined in builder/builder.ts:212
Parameters
Name | Details |
---|---|
callback
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
onSuccess()
onSuccess()
Preview
onSuccess<ErrorType>(callback)
Description
Method for intercepting success responses.
Defined in builder/builder.ts:194
Parameters
Name | Details |
---|---|
callback
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
removeEffect()
removeEffect()
Preview
removeEffect(effect)
Description
Remove effects from builder
Defined in builder/builder.ts:231
Parameters
Name | Details |
---|---|
effect
|
|
Return
this
setClient()
setClient()
Preview
setClient(callback)
Description
Set custom http client to handle graphql, rest, firebase or other
Defined in builder/builder.ts:168
Parameters
Name | Details |
---|---|
callback
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
setCommandConfig()
setCommandConfig()
Preview
setCommandConfig(callback)
Description
This method allows to configure global defaults for the command configuration like method, auth, deduplication etc.
Defined in builder/builder.ts:101
Parameters
Name | Details |
---|---|
callback
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
setDebug()
setDebug()
Preview
setDebug(debug)
Description
This method enables the logger usage and display the logs in console
Defined in builder/builder.ts:111
Parameters
Name | Details |
---|---|
debug
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
setHeaderMapper()
setHeaderMapper()
Preview
setHeaderMapper(headerMapper)
Description
Set the custom header mapping function
Defined in builder/builder.ts:152
Parameters
Name | Details |
---|---|
headerMapper
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
setLogger()
setLogger()
Preview
setLogger(callback)
Description
Set the new logger instance to the builder
Defined in builder/builder.ts:127
Parameters
Name | Details |
---|---|
callback
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
setLoggerSeverity()
setLoggerSeverity()
Preview
setLoggerSeverity(severity)
Description
Set the logger severity of the messages displayed to the console
Defined in builder/builder.ts:119
Parameters
Name | Details |
---|---|
severity
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
setPayloadMapper()
setPayloadMapper()
Preview
setPayloadMapper(payloadMapper)
Description
Set the request payload mapping function which get triggered before request get send
Defined in builder/builder.ts:160
Parameters
Name | Details |
---|---|
payloadMapper
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
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 builder/builder.ts:135
Parameters
Name | Details |
---|---|
queryParamsConfig
|
|
Return
Builder<GlobalErrorType, RequestConfigType>
setStringifyQueryParams()
setStringifyQueryParams()
Preview
setStringifyQueryParams(stringifyFn)
Description
Set the custom query params stringify method to the builder
Defined in builder/builder.ts:144
Parameters
Name | Details |
---|---|
stringifyFn
| Custom callback handling query params stringify
|
Return
Builder<GlobalErrorType, RequestConfigType>
__modifyAuth()
__modifyAuth()
Preview
__modifyAuth(command)
Description
Helper used by http client to apply the modifications on response error
Defined in builder/builder.ts:241
Parameters
Name | Details |
---|---|
command
|
|
Return
Promise<CommandInstance>
__modifyErrorResponse()
__modifyErrorResponse()
Preview
__modifyErrorResponse(response, command)
Description
Private helper to run async on-error response processing
Defined in builder/builder.ts:251
Parameters
Return
Promise<ClientResponseType<any, GlobalErrorType>>
__modifyRequest()
__modifyRequest()
Preview
__modifyRequest(command)
Description
Private helper to run async pre-request processing
Defined in builder/builder.ts:246
Parameters
Name | Details |
---|---|
command
|
|
Return
Promise<CommandInstance>
__modifyResponse()
__modifyResponse()
Preview
__modifyResponse(response, command)
Description
Private helper to run async response processing
Defined in builder/builder.ts:263
Parameters
Return
Promise<ClientResponseType<any, GlobalErrorType>>