API integration
Guide to backend API integration and usage
Overview
The API integration uses:
- OpenAPI schema generation with drf-spectacular
- Generated TypeScript clients in
@lcmd/apivia@hey-api/openapi-ts - Shared client setup, request helpers, and TanStack Query hooks in
@lcmd/logic - Scalar for interactive API documentation
API versioning
The API follows a versioned URL structure:
| Endpoint | Description |
|---|---|
/api/v1/ | API v1 endpoints |
/api/v1/schema/ | OpenAPI schema for v1 |
/api/v1/docs/ | Interactive API documentation (Scalar) |
Legacy URLs (/api/schema/, /reference/) redirect to the v1 equivalents for backward compatibility.
API documentation
Access the interactive API documentation at:
- Local: http://localhost:8000/api/v1/docs/
- Production: https://lcmd-app.epfl.ch/api/v1/docs/
The documentation is powered by Scalar and provides:
- Interactive request builder
- Code examples in multiple languages
- Schema exploration
API clients
packages/api contains generated clients for both backend surfaces:
@lcmd/api: DRF API client, SDK functions, types, Zod schemas, and TanStack Query options@lcmd/api/allauth: django-allauth headless browser API client, SDK functions, types, Zod schemas, and TanStack Query options
Application code should usually consume the higher-level helpers in @lcmd/logic instead of configuring generated clients per call site. @lcmd/logic/clients centralizes base URL, cookie credentials, CSRF headers, and unauthorized handling.
Schema management
Updating OpenAPI schemas
After backend changes, regenerate the committed schemas and TypeScript clients:
pnpm turbo run codegen --filter=@lcmd/apiThis runs the backend schema generator, writes packages/api/schema.yaml and packages/api/allauth-schema.yaml, then regenerates packages/api/src/.
Client-side requests
For web app API requests:
- Use TanStack Query through
@lcmd/logicquery hooks and request helpers - Keep generated API calls inside reusable domain modules
- Let the configured clients handle same-origin cookies and CSRF headers