Skip to content

Configuration

Zlient is highly configurable at both the client level and the request level.

Client Options

Pass these to new HttpClient(options).

OptionTypeDescription
baseUrlsBaseUrlMapRequired. Map of service names to URLs. Must include default.
fetchFetchLikeCustom fetch implementation. Defaults to globalThis.fetch.
headersRecord<string, string>Default headers applied to every request.
authAuthProviderAuthentication strategy (see Auth Guide).
retryRetryPolicyGlobal retry configuration (see Error Handling).
timeout{ requestTimeoutMs?: number }Global timeout for all requests.
interceptorsInterceptorsHooks for request/response lifecycle.
loggerLoggerLogger implementation.
metricsMetricsCollectorMetrics collector implementation.
onUnauthenticated(response: Response) => Promise<boolean> | booleanCalled on a 401 response. Return true to retry the request once (e.g. after refreshing a token), or false to surface the 401 as-is. See Auth Guide.

BaseUrlMap

Zlient supports multiple services in one client instance.

typescript
const client = new HttpClient({
  baseUrls: {
    default: 'https://api.example.com',
    auth: 'https://auth.example.com',
    cdn: 'https://cdn.example.com',
  },
});

Using a specific service:

typescript
await getProfile({ baseUrlKey: 'auth' });

Request Options

Untyped requests (client.get/post/put/patch/delete)

These accept a flat options object as the second argument:

typescript
await client.get('/profile', {
  baseUrlKey: 'cdn', // Use a different entry from baseUrls
  skipAuth: true, // Skip authentication for this request only
  skipRetry: true, // Skip retry logic for this request only
  headers: { 'Cache-Control': 'no-cache' }, // Merged with default headers
  signal: controller.signal, // AbortSignal for cancellation
  query: { debug: 'true' }, // Appended to the URL
});

Typed endpoints (createEndpoint/createSSE/createWebSocket)

Per-call params only cover request shape — data, query, pathParams, headers, and signal:

typescript
await getUser({
  pathParams: { id: '123' },
  query: { includePosts: true },
  headers: { 'Cache-Control': 'no-cache' },
  signal: controller.signal,
});

Behavioral flags like baseUrlKey, skipAuth, skipRetry, skipRequestValidation, and skipResponseValidation are fixed per-endpoint, set once in the advanced block when you define the endpoint (see Error Handling for an example), not per call.

Released under the MIT License.