Skip to Content
✨ New: Auth Plugin. JWT, OAuth2, API Key, and more authentication strategies out of the box. Read more... πŸŽ‰
Configuration

Configuration

Client Config (ApiConfig)

OptionTypeRequiredDescription
baseUrlstringβœ…Base URL prepended to all endpoint paths
defaultHeadersRecord<string, string>β€”Headers sent with every request
fetchtypeof fetchβ€”Custom fetch instance (for mocking, polyfills, etc.)
hooksHooksβ€”Global hooks applied to every request
pluginsPlugin[]β€”Plugins to extend functionality
const api = createApiClient(endpoints, { baseUrl: 'https://api.example.com', defaultHeaders: { 'Content-Type': 'application/json', 'X-Client-Version': '1.0.0', }, fetch: customFetch, hooks: { beforeRequest: async (url, init) => ({ url, init }), afterResponse: async (response) => response, onError: async (error) => console.error(error), }, plugins: [cache({ ttl: 300 }), retryPlugin({ maxRetries: 3 })], });

Endpoint Config

PropertyTypeRequiredDescription
method'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'βœ…HTTP method
pathstring | ((input: TInput) => string)βœ…Static path or function returning a path
handlerCustomHandler<TInput, TOutput>β€”Custom handler for non-JSON or special requests
hooksHooksβ€”Endpoint-specific hooks

Prefer the get(), post(), etc. helpers over constructing endpoint configs manually β€” they set method for you.

Group Config

PropertyTypeDescription
endpointsRecord<string, EndpointConfig>Direct endpoint children of this group
groupsRecord<string, GroupConfig>Nested sub-groups
hooksHooksHooks applied to all endpoints in this group (and sub-groups)
basePathstringPath prefix prepended to all endpoint paths in this group (recursive)

Hooks Interface

type Hooks = { beforeRequest?: (url: string, init: RequestInit) => Promise<{ url: string; init: RequestInit }>; afterResponse?: (response: Response, url: string, init: RequestInit) => Promise<Response>; onError?: (error: unknown) => Promise<void> | void; };