Installation
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
Request and Response Objects
Access Hapi’s request and response toolkit in your controllers:Pre-handlers (Middleware)
Use Hapi’s pre-handler functionality with tsoa:Error Handling with Boom
Use@hapi/boom for consistent error responses:
Common Boom Errors
Server Configuration
CORS
Enable CORS for your API:Payload Size
Configure maximum payload size:Validation
Customize validation behavior:Base Path
Configure a base path for all routes:tsoa.json
Query Parameters
Headers
Response Toolkit
While tsoa handles most response scenarios, you can access the response toolkit for advanced use cases:Lifecycle Events
Hapi has a rich lifecycle with extension points:Plugins
Register Hapi plugins with your server:Next Steps
File Uploads
Learn how to handle file uploads with Hapi
Authentication
Use Hapi’s auth strategies with tsoa
Validation
Implement request validation
Dependency Injection
Use IoC containers with your controllers