2026-01-01 23:29:31 +01:00
|
|
|
# API Client
|
|
|
|
|
|
|
|
|
|
This directory contains the auto-generated TypeScript API client for the STA backend.
|
|
|
|
|
|
|
|
|
|
## Files
|
|
|
|
|
|
|
|
|
|
- `schema.ts` - Auto-generated OpenAPI type definitions (do not edit manually)
|
|
|
|
|
- `client.ts` - API client instance with type-safe methods
|
|
|
|
|
|
|
|
|
|
## Regenerating the Client
|
|
|
|
|
|
|
|
|
|
To regenerate the TypeScript client after backend API changes:
|
|
|
|
|
|
|
|
|
|
1. Start the backend server:
|
|
|
|
|
```bash
|
2026-05-14 21:41:34 +02:00
|
|
|
just backend run
|
2026-01-01 23:29:31 +01:00
|
|
|
```
|
|
|
|
|
|
2026-05-14 21:41:34 +02:00
|
|
|
2. Execute the update script:
|
2026-01-01 23:29:31 +01:00
|
|
|
```bash
|
2026-05-14 21:41:34 +02:00
|
|
|
just frontend sync
|
2026-01-01 23:29:31 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Usage Example
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
import { apiClient } from '@/api/client';
|
|
|
|
|
|
|
|
|
|
// GET request
|
|
|
|
|
const { data, error } = await apiClient.GET('/api/health');
|
|
|
|
|
if (error) {
|
|
|
|
|
console.error('Health check failed:', error);
|
|
|
|
|
} else {
|
|
|
|
|
console.log('Server is healthy');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET request with response data
|
|
|
|
|
const { data: meta, error: metaError } = await apiClient.GET('/api/meta');
|
|
|
|
|
if (metaError) {
|
|
|
|
|
console.error('Failed to get metadata:', metaError);
|
|
|
|
|
} else {
|
|
|
|
|
console.log('App name:', meta.name);
|
|
|
|
|
console.log('App version:', meta.version);
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
|
|
The API base URL can be configured via the `VITE_API_BASE_URL` environment variable.
|
|
|
|
|
Create a `.env` file in the project root:
|
|
|
|
|
|
|
|
|
|
```env
|
|
|
|
|
VITE_API_BASE_URL=http://localhost:3100
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
For production builds, set the environment variable to point to your deployed backend.
|