API Client and Types
Avoid contract drift between frontend and backend.
Recommended approach
Generate a typed API client from backend OpenAPI schema.
- Backend: generate OpenAPI (for example with NestJS Swagger)
- Frontend: generate client/types (for example with
swagger-typescript-api)
This keeps request/response contracts synchronized and discoverable.
Alternatives and when to choose them
- tRPC/oRPC/RPC-style shared contract when both sides can share runtime contracts directly.
Implementation checklist
- Add
generate:clientscript and CI check for generated diffs. - Version APIs with deprecation policy.
- Keep transport concerns separate from domain mapping.
Common pitfalls
- Editing generated files manually.
- Using backend DTOs directly in UI instead of view models where needed.