Skip to main content

HTTP client

ApiClient

createApiClient(baseUrl, options) returns an client with:

MethodDescription
getGET request
postPOST with body
putPUT with body
patchPATCH with body
deleteDELETE
executearbitrary HTTP method

All methods return Bluebird promises of AxiosResponse<T>.

RequestConfig

interface RequestConfig<Body> {
query?: Record<string, unknown>;
headers?: Record<string, unknown>;
body?: Body;
responseType?: ResponseType;
skipAuthentication?: boolean;
retryAttempts?: number;
retryNumber?: number;
}
  • query — serialized with stringifyQueryParams (nested objects supported)
  • withCredentials — cookies sent automatically (Axios default in this client)
  • retryAttempts — defaults to 3 with exponential backoff (cap 30s)
  • skipAuthentication — skip unauthorized redirect on matching status codes

Unauthorized handling

ApiClientOptions:

{
unauthorizedRedirectPath?: string; // default '/'
unauthorizedStatus?: number[]; // default [401]
}

When a response matches, the browser navigates to the redirect path unless skipAuthentication is set on the request.

Query string helper

import { stringifyQueryParams } from '@ekz/api';

stringifyQueryParams({ filter: { active: true }, page: 1 });

Useful outside the client when building URLs manually.