@dazl/internal-api-client
v1.28.3
Published
Type-safe SDK for Dazl Internal APIs, generated from OpenAPI specifications
Readme
Dazl Internal API Client
Type-safe SDK for Dazl Internal APIs, generated from OpenAPI specifications.
Installation
npm install @dazl/internal-api-clientUsage
Create a client instance with createClient and pass it to every API call:
import { createClient } from '@dazl/internal-api-client/client';
import { Billing } from '@dazl/internal-api-client';
const client = createClient({
baseUrl: 'http://api-server-url/private',
headers: {
'x-api-key': 'my-secret-api-key',
},
});
const customerInfoRes = await Billing.getCustomerInfoByDazlId({
path: { dazlId: 'USER_DAZL_ID' },
client,
});
if (customerInfoRes.error) {
throw new Error(customerInfoRes.error.message);
}
const customerInfo = customerInfoRes.data;Acting on behalf of a user
The recommended pattern is to create a per-request client with the x-user-id header baked in, and store it on the request context:
// middleware — runs once per request
const userClient = createClient({
baseUrl: 'http://api-server-url/private',
headers: {
'x-api-key': 'my-secret-api-key',
'x-user-id': context.userId, // userId from the authenticated request
},
});
context.apiClient = userClient;
// handler — no need to pass headers each time
const customerInfoRes = await Billing.getCustomerInfoByDazlId({
path: { dazlId: 'USER_DAZL_ID' },
client: context.apiClient,
});Related Docs
Additional client fetch documentation can be found here: https://heyapi.dev/openapi-ts/clients/fetch
