Getting Started
Installation
bash
npm install zlient
# or
bun add zlientThen install your preferred validation library:
bash
npm install zodbash
npm install valibotbash
npm install arktypeStandard Schema
Zlient supports any validation library that implements Standard Schema. This includes Zod v4+, Valibot, ArkType, and more!
Quick Start
1. Initialize Client
typescript
import { HttpClient } from 'zlient';
const client = new HttpClient({
baseUrls: {
default: 'https://api.example.com',
},
});2. Define an Endpoint
Use your preferred validation library:
typescript
import { z } from 'zod';
const getUser = client.createEndpoint({
method: 'GET',
path: (p) => `/users/${p.id}`,
pathParams: z.object({ id: z.string() }),
response: z.object({
id: z.string(),
name: z.string(),
}),
});typescript
import * as v from 'valibot';
const getUser = client.createEndpoint({
method: 'GET',
path: (p) => `/users/${p.id}`,
pathParams: v.object({ id: v.string() }),
response: v.object({
id: v.string(),
name: v.string(),
}),
});typescript
import { type } from 'arktype';
const getUser = client.createEndpoint({
method: 'GET',
path: (p) => `/users/${p.id}`,
pathParams: type({ id: 'string' }),
response: type({
id: 'string',
name: 'string',
}),
});3. Call it
typescript
const user = await getUser({
pathParams: { id: '123' },
});