Skip to Content
🎉 New release with new features and improvements! V0.0.2 Release →

Custom HTTP Client

You can provide a custom HTTP client function if you need to use a different HTTP library.

Default Client Function

by default, the SDK uses fetch to make requests. see the internal implementation here .

export const defaultClientFn: BshClientFn = async (params) => { return fetch( params.path, { method: params.options.method, body: params.options.requestFormat === 'form' ? params.options.body as BodyInit : params.options.body ? JSON.stringify(params.options.body) : undefined, headers: params.options.headers, } ); };

You can use this function as a reference to create your own custom HTTP client function.

Types

export type BshClientFnParams<T = unknown, R = T> = { path: string, options: { method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', // The HTTP method responseType?: 'json' | 'blob' | 'text' | 'arrayBuffer', // The response type requestFormat?: 'json' | 'text' | 'form', // The request format body?: T | BshSearch<T> | unknown, // The request body formData?: FormData, // The form data queryParams?: Record<string, string>, // The query parameters headers?: Record<string, string>, // The headers }, bshOptions: BshCallbackParams<T, R>, api?: string } export type BshClientFn = <T = unknown>(params: BshClientFnParams<T>) => Promise<Response>;
OptionDescription
pathThe URL path of the request
optionsThe options of the request
options.methodThe HTTP method
options.responseTypeThe response type
options.requestFormatThe request format
options.bodyThe request body
options.formDataThe form data
options.queryParamsThe query parameters
options.headersThe headers
bshOptionsThe callbacks functions (onSuccess, onError, onDownload)
bshOptions.onSuccessThe callback function for successful requests
bshOptions.onErrorThe callback function for error requests
bshOptions.onDownloadThe callback function for download requests
apiThe API method name