Overview
TheIntegration class generates TypeScript code containing:
- Input/output types for all your endpoints
- A fully-typed client for making API requests
- Runtime validation of request and response data
- Support for Server-Sent Events (SSE) subscriptions
Quick Start
Create a script to generate your client:generate-client.ts
Configuration Options
Basic Options
The TypeScript compiler API. Import from the
typescript package.Your API routing configuration.
Your API server configuration.
The base URL where your API is hosted.
Advanced Options
What to generate:
"types"- Only TypeScript types (for DIY solutions)"client"- Full client with types and implementation
Name for the generated client class.
Name for the generated subscription class (for SSE).
Schema for responses without body (like 204 No Content).
Generate HEAD method for each GET endpoint (Express feature).
Custom handling rules for branded schemas. See the Integration class documentation for details.
Using the Generated Client
Basic Usage
The generated client provides type-safe methods for all your endpoints:frontend-app.ts
Path Parameters
The client automatically substitutes path parameters:Custom Implementation
You can provide a custom implementation function to use your preferred HTTP library:Server-Sent Events (SSE)
For endpoints that useEventStreamFactory, use the generated Subscription class:
Pagination Support
The client includes ahasMore() method for paginated endpoints:
Formatting Options
Using Prettier
TheprintFormatted() method automatically uses Prettier if installed:
Without Formatting
For unformatted output:Async Creation
If you want to avoid importing TypeScript yourself, use the asynccreate() method:
Types-Only Generation
For DIY solutions where you want to implement your own client:- Input types for all endpoints
- Response types for all endpoints
- Path and method type unions
- Request/response interfaces
Complete Example
Here’s a full example with multiple features:generate-client.ts
frontend-usage.ts
The generated client requires TypeScript 4.1 or higher to consume.
Benefits
Type Safety
Compile-time verification of request parameters and response handling
Auto-Complete
Full IDE support with autocomplete for all endpoints and their types
Refactoring
Changes to your API automatically surface as TypeScript errors in frontend
Documentation
Types serve as inline documentation for API consumers
Next Steps
- Learn about OpenAPI documentation generation
- Explore branded types
- Set up pagination in your endpoints