Routing Controllers lets you define class-based HTTP handlers with decorators on top of Express or Koa. Routes, parameters, and responses are declared in TypeScript instead of manual wiring.
Overview
Routing Controllers is a TypeScript library that registers controller classes whose methods handle incoming HTTP requests. You attach decorators for paths, verbs, and injected parameters so request handling stays organized in one place per resource.
It works with either Express or Koa: you bootstrap through createExpressServer, createKoaServer, or attach controllers to an existing app with useExpressServer or useKoaServer. Optional @JsonController marks REST-style endpoints that always use JSON request and response bodies.
Decorators cover route and query parameters, bodies, headers, cookies, sessions, uploads, custom status codes, redirects, templates, and thrown HTTP errors. class-transformer and class-validator integrate for object binding and validation; CORS, middlewares, interceptors, and authorization helpers can apply per action, per controller, or globally.
You can load controllers from directories, prefix routes, return promises from actions, and plug in dependency injection containers. Middleware may be existing Express or Koa modules or custom classes and functions scoped to specific handlers.
Key features
- Class-based controllers with decorators
- Express and Koa integration
- Parameter injection and validation
- JSON REST controller mode
- Middleware and interceptor hooks
- Authorization and custom HTTP errors
- File upload via multer
- CORS configuration option
Use cases
- Structured REST APIs in TypeScript
- Express apps with declarative routes
- Koa apps with declarative routes
- Validated request DTOs in controllers