HTTP client
ApiClient
createApiClient(baseUrl, options) returns an client with:
| Method | Description |
|---|---|
get | GET request |
post | POST with body |
put | PUT with body |
patch | PATCH with body |
delete | DELETE |
execute | arbitrary 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 withstringifyQueryParams(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.