Skip to main content
Skip to main content

Client

swaps.internal.Client

Properties

axiosClientAxiosInstanceRequired
configConfigRequired

Methods

createClient

createClient(config): AxiosInstance

Creates the axios client used for requests As part of the creation, we configure the retry conditions and the exponential backoff approach.

Parameters

configConfigRequired
user supplied configurations

Returns

AxiosInstance

AxiosInstanceAxiosInstanceRequired

normalizeHeader

normalizeHeader(header): string

Parameters

headerstringRequired

Returns

string

stringstring

normalizeHeaders

normalizeHeaders(obj): Record<string, any>

Parameters

objobjectRequired

Returns

Record<string, any>

RecordRecord<string, any>Required

request

request(method, path, payload?, options?, customHeaders?): Promise<any>

Axios request

Parameters

methodRequestMethodRequired
request method
pathstringRequired
request path
payloadRecord<string, any>Required
request payload

Default: `{}`

optionsRequestOptionsRequired
axios configuration

Default: `{}`

customHeadersRecord<string, any>Required
custom request headers

Default: `{}`

Returns

Promise<any>

PromisePromise<any>Required

requiresAuthentication

requiresAuthentication(path, method): boolean

Parameters

pathanyRequired
methodanyRequired

Returns

boolean

booleanboolean

setHeaders

setHeaders(userHeaders, method, path, customHeaders?): AxiosRequestHeaders

Creates all the initial headers. We add the idempotency key, if the request is configured to retry.

Parameters

userHeadersRequestOptionsRequired
user supplied headers
methodRequestMethodRequired
request method
pathstringRequired
request path
customHeadersRecord<string, any>Required
user supplied headers

Default: `{}`

Returns

AxiosRequestHeaders

AxiosRequestHeadersRecord<string, string>Required

shouldRetryCondition

shouldRetryCondition(err, numRetries, maxRetries): boolean

Parameters

errAxiosError<any, any>Required
numRetriesnumberRequired
maxRetriesnumberRequired

Returns

boolean

booleanboolean
Was this section helpful?