96 lines
2.0 KiB
Markdown

# @olli/api-client-backend
Type-safe API client for the backend service, auto-generated from OpenAPI spec using `@hey-api/openapi-ts`.
This is a **just-in-time (JIT) package** - consuming apps compile the TypeScript source directly for optimal performance.
## Installation
Add to your app's dependencies:
```json
{
"dependencies": {
"@olli/api-client-backend": "workspace:*"
}
}
```
## Usage
### Using SDK Functions (Recommended)
```typescript
import { getDemoPersons, postDemoPersons } from '@olli/api-client-backend';
import { client } from '@olli/api-client-backend/client';
// Configure the client once
client.setConfig({
baseUrl: 'http://localhost:3003',
headers: {
'Authorization': 'Bearer token'
}
});
// Use type-safe SDK functions
const { data: persons } = await getDemoPersons();
const { data: newPerson } = await postDemoPersons({
body: {
first_name: 'John',
gender: 'man',
metadata: {
login_at: new Date().toISOString(),
ip: null,
agent: null,
plan: 'free'
}
}
});
```
### Direct Client Access
```typescript
import { client } from '@olli/api-client-backend/client';
const response = await client.get({ url: '/demo/persons' });
```
## Exports
- `@olli/api-client-backend` - All generated SDK functions and types
- `@olli/api-client-backend/client` - Client instance and configuration
## Development
### Generate Client
The client is automatically generated from the backend's OpenAPI spec:
```bash
# Generate from OpenAPI spec
turbo run generate --filter=@olli/api-client-backend
# Or manually
cd apps/backend && pnpm export-openapi
cd ../../packages/api-client-backend && pnpm generate
```
### Type Checking
```bash
pnpm check-types
```
## Architecture
This package follows Turborepo best practices as a **JIT (Just-In-Time) package**:
- ✅ No build step - TypeScript source consumed directly
- ✅ Faster hot reload in development
- ✅ Single compilation by consuming app
- ✅ Better tree-shaking and bundle optimization
- ✅ TypeScript project references for incremental builds