Installation
Configure tsoa
Create a
tsoa.json configuration file in your project root:tsoa.json
The
middleware field must be set to "express" for Express.js projects.Create a Controller
Create your first controller with tsoa decorators:
src/controllers/userController.ts
Generate Routes and Spec
Add scripts to your Generate routes and OpenAPI spec:This creates:
package.json:package.json
src/routes.ts- Generated route handlersbuild/swagger.json- OpenAPI specification
Router vs Application
tsoa supports both ExpressApplication and Router instances:
Request Context
Access the raw Express request and response objects in your controllers:Middleware Integration
Apply Express middleware to specific routes or controllers:Custom Base Path
Configure a base path for all routes:tsoa.json
/api/v1.
Advanced Configuration
Response Headers
Set custom response headers:Multiple Status Codes
Document multiple possible status codes:Common Patterns
Query Parameters
Request Headers
Next Steps
File Uploads
Learn how to handle file uploads with multer
Authentication
Secure your API with authentication
Validation
Implement request validation
Dependency Injection
Use IoC containers with your controllers