Instruction file imported from blackmouse572/ecbot (
.github/instructions/packages/client.instructions.md). Copyright stays with the author.
API Client Package Instructions
Overview
The API client is automatically generated from the OpenAPI specification using openapi-ts.
Generation
Run this command to regenerate the client:
pnpm generate:client
This reads the OpenAPI spec from the API and generates TypeScript types and client code.
Usage
import { client } from "@eccho/client";
// Configure client
client.setConfig({
baseUrl: "http://localhost:3000",
headers: {
Authorization: `Bearer ${token}`,
},
});
// Use generated endpoints
const response = await client.getUser({ id: "123" });
const users = await client.listUsers({ page: 1, perPage: 10 });
Type Safety
The generated client provides full TypeScript support:
import type { UserEntity, UserCreateDto } from "@eccho/client";
const createUser = async (dto: UserCreateDto): Promise<UserEntity> => {
const response = await client.createUser({ body: dto });
return response.data;
};
Error Handling
try {
const user = await client.getUser({ id: userId });
} catch (error) {
if (error.status === 404) {
console.error("User not found");
} else if (error.status === 401) {
console.error("Unauthorized");
}
}
Best Practices
- Regenerate regularly - Keep client in sync with API changes
- Don't edit manually - Client is auto-generated
- Use types - Leverage generated TypeScript types
- Configure globally - Set baseUrl and headers once
- Handle errors - Check error status codes
- Version compatibility - Ensure API and client versions match