Skip to main content
Version: v8.0.0

Adapter


Import
import { Adapter } from "@hyper-fetch/core"

Parameters

class Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType> {
constructor(options: { defaultExtra: Extra; defaultMethod: MethodType; defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>; name: string; systemErrorExtra: Extra; systemErrorStatus: StatusType }) {};
unstable_queryParamsMapperConfig: Parameters<QueryParamsMapperType>[1];
unstable_queryParamsMapper: QueryParamsMapperType;
unstable_payloadMapperConfig: Parameters<PayloadMapperType>[1];
unstable_payloadMapper: PayloadMapperType;
unstable_headerMapperConfig: Parameters<HeaderMapperType>[1];
unstable_headerMapper: HeaderMapperType;
unstable_endpointMapperConfig: Parameters<EndpointMapperType>[1];
unstable_endpointMapper: EndpointMapperType;
systemErrorStatus: StatusType;
systemErrorExtra: Extra;
options: { defaultExtra: Extra; defaultMethod: MethodType; defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>; name: string; systemErrorExtra: Extra; systemErrorStatus: StatusType };
name: string;
logger: LoggerMethods;
initialized: boolean;
defaultRequestOptions: RequestOptionsType<EndpointType, AdapterOptions, MethodType>;
defaultMethod: MethodType;
defaultExtra: Extra;
client: ClientInstance;
unstable_devtoolsEndpointGetter() => (endpoint: string) => string;
unstable_fetcher() => AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>;
unstable_getAdapterDefaults() => (request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>) => AdapterOptions;
unstable_getRequestDefaults() => (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>;
unstable_internalErrorMapping() => (error: TimeoutError | AbortError | DeletedError | RequestProcessingError | UnexpectedError) => any;
unstable_onInitializeCallback() => (options: { client: ClientInstance }) => void;
fetch(request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>, requestId: string) => Promise<RequestResponseType<RequestInstance>>;
initialize(client: ClientInstance) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
onInitialize(callback: (options: { client: ClientInstance }) => void) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setAdapterDefaults(callback: (request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>) => AdapterOptions) => this;
setDefaultExtra(extra: Extra) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setDefaultMethod(method: MethodType) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setDevtoolsEndpointGetter(callback: (endpoint: string) => string) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setEndpointMapper<NewEndpointMapper>(endpointMapper: NewEndpointMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, NewEndpointMapper, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setEndpointMapperConfig<NewEndpointMapperConfig>(config: NewEndpointMapperConfig) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setFetcher(fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setHeaderMapper<NewMapper>(headerMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, NewMapper, PayloadMapperType>;
setHeaderMapperConfig<NewHeaderMapperConfig>(config: NewHeaderMapperConfig) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setInternalErrorMapping(callback: (error: TimeoutError | AbortError | DeletedError | RequestProcessingError | UnexpectedError) => any) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setPayloadMapper<NewMapper>(payloadMapper: NewMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, NewMapper>;
setPayloadMapperConfig<NewPayloadMapperConfig>(config: NewPayloadMapperConfig) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setQueryParamsMapper<NewQueryParamsMapper>(queryParamsMapper: NewQueryParamsMapper) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, NewQueryParamsMapper, HeaderMapperType, PayloadMapperType>;
setQueryParamsMapperConfig<NewQueryParamsMapperConfig>(config: NewQueryParamsMapperConfig) => Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>;
setRequestDefaults(callback: undefined | (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>) => this;
}
Parameters
NameTypeDescription
options
{ defaultExtra: Extra; defaultMethod: MethodType; defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>; name: string; systemErrorExtra: Extra; systemErrorStatus: StatusType }

Properties

client

Type
ClientInstance

defaultExtra

Type
Extra

defaultMethod

Type
MethodType

defaultRequestOptions

Type
RequestOptionsType<EndpointType, AdapterOptions, MethodType>

initialized

Type
boolean

logger

Type
LoggerMethods

name


Defaults


Type
string

options

Type
{ defaultExtra: Extra; defaultMethod: MethodType; defaultRequestOptions?: RequestOptionsType<EndpointType, AdapterOptions, MethodType>; name: string; systemErrorExtra: Extra; systemErrorStatus: StatusType }

systemErrorExtra

Type
Extra

systemErrorStatus

Type
StatusType

unstable_endpointMapper

Method to get the endpoint for the adapter request.

Type
EndpointMapperType

unstable_endpointMapperConfig

Type
Parameters<EndpointMapperType>[1]

unstable_headerMapper

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

Type
HeaderMapperType

unstable_headerMapperConfig

Type
Parameters<HeaderMapperType>[1]

unstable_payloadMapper

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

Type
PayloadMapperType

unstable_payloadMapperConfig

Type
Parameters<PayloadMapperType>[1]

unstable_queryParamsMapper

Method to get request data and transform them to the required format.

Type
QueryParamsMapperType

unstable_queryParamsMapperConfig

Type
Parameters<QueryParamsMapperType>[1]

Methods

fetch()

Preview
fetch(request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>, requestId: string)
Parameters
Parameters
NameTypeDescription
request
ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>
requestId
string
Returns
Promise<RequestResponseType<RequestInstance>>

initialize()

Preview
initialize(client: ClientInstance)
Parameters
Parameters
NameTypeDescription
client
ClientInstance
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

onInitialize()

Preview
onInitialize(callback: (options: { client: ClientInstance }) => void)
Parameters
Parameters
NameTypeDescription
callback
(options: { client: ClientInstance }) => void
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setAdapterDefaults()

Set the adapter default options added to every sent request

Preview
setAdapterDefaults(callback: (request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>) => AdapterOptions)
Parameters
Parameters
NameTypeDescription
callback
(request: ExtendRequest<RequestInstance, { client: Client<any, Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>> }>) => AdapterOptions
Returns
this

setDefaultExtra()

Preview
setDefaultExtra(extra: Extra)
Parameters
Parameters
NameTypeDescription
extra
Extra
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setDefaultMethod()


Methods


Preview
setDefaultMethod(method: MethodType)
Parameters
Parameters
NameTypeDescription
method
MethodType
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setDevtoolsEndpointGetter()

Preview
setDevtoolsEndpointGetter(callback: (endpoint: string) => string)
Parameters
Parameters
NameTypeDescription
callback
(endpoint: string) => string
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setEndpointMapper()

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

Preview
setEndpointMapper<NewEndpointMapper>(endpointMapper: NewEndpointMapper)
Parameters
Parameters
NameTypeDescription
endpointMapper
NewEndpointMapper
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, NewEndpointMapper, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setEndpointMapperConfig()

Preview
setEndpointMapperConfig<NewEndpointMapperConfig>(config: NewEndpointMapperConfig)
Parameters
Parameters
NameTypeDescription
config
NewEndpointMapperConfig
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setFetcher()


Fetching


Preview
setFetcher(fetcher: AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>)
Parameters
Parameters
NameTypeDescription
fetcher
AdapterFetcherType<Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>>
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setHeaderMapper()

Set the custom header mapping function

Preview
setHeaderMapper<NewMapper>(headerMapper: NewMapper)
Parameters
Parameters
NameTypeDescription
headerMapper
NewMapper
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, NewMapper, PayloadMapperType>

setHeaderMapperConfig()

Preview
setHeaderMapperConfig<NewHeaderMapperConfig>(config: NewHeaderMapperConfig)
Parameters
Parameters
NameTypeDescription
config
NewHeaderMapperConfig
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setInternalErrorMapping()

Preview
setInternalErrorMapping(callback: (error: TimeoutError | AbortError | DeletedError | RequestProcessingError | UnexpectedError) => any)
Parameters
Parameters
NameTypeDescription
callback
(error: TimeoutError | AbortError | DeletedError | RequestProcessingError | UnexpectedError) => any
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setPayloadMapper()

Set the request payload mapping function which gets triggered before request is send

Preview
setPayloadMapper<NewMapper>(payloadMapper: NewMapper)
Parameters
Parameters
NameTypeDescription
payloadMapper
NewMapper
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, NewMapper>

setPayloadMapperConfig()

Preview
setPayloadMapperConfig<NewPayloadMapperConfig>(config: NewPayloadMapperConfig)
Parameters
Parameters
NameTypeDescription
config
NewPayloadMapperConfig
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setQueryParamsMapper()

Set the query params mapping function which get triggered before request get sent

Preview
setQueryParamsMapper<NewQueryParamsMapper>(queryParamsMapper: NewQueryParamsMapper)
Parameters
Parameters
NameTypeDescription
queryParamsMapper
NewQueryParamsMapper
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, NewQueryParamsMapper, HeaderMapperType, PayloadMapperType>

setQueryParamsMapperConfig()

Preview
setQueryParamsMapperConfig<NewQueryParamsMapperConfig>(config: NewQueryParamsMapperConfig)
Parameters
Parameters
NameTypeDescription
config
NewQueryParamsMapperConfig
Returns
Adapter<AdapterOptions, MethodType, StatusType, Extra, QueryParams, DefaultQueryParams, EndpointType, EndpointMapperType, QueryParamsMapperType, HeaderMapperType, PayloadMapperType>

setRequestDefaults()

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

Preview
setRequestDefaults(callback: undefined | (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>)
Parameters
Parameters
NameTypeDescription
callback
undefined | (options: RequestOptionsType<EndpointType, AdapterOptions, MethodType>) => Partial<RequestOptionsType<EndpointType, AdapterOptions, MethodType>>
Returns
this