TypeScript Client Guide
Installation
If you copy the generated client into your frontend:
# From the frontend repo
npm i axios
Usage
import { Configuration } from './api';
import { DefaultApi } from './api';
const config = new Configuration({
basePath: process.env.NEXT_PUBLIC_API_BASE_URL,
baseOptions: {
headers: { 'x-api-key': process.env.NEXT_PUBLIC_API_KEY! },
timeout: 10_000,
}
});
const api = new DefaultApi(config);
async function health() {
const res = await api.healthHandler();
console.log(res.data);
}
health();
React Query Example
import { useQuery } from '@tanstack/react-query';
import { DefaultApi, Configuration } from './api';
const api = new DefaultApi(new Configuration({ basePath: '/api' }));
export function useSystemHealth() {
return useQuery({
queryKey: ['system-health'],
queryFn: () => api.healthHandler().then(r => r.data),
staleTime: 10_000,
});
}