Skip to main content

Controllers

A route in RapidREST is a plain class decorated with @Route, with one method per endpoint, each decorated with the HTTP verb it handles. There's no router file, no app.get(path, handler) calls to make, the class is discovered and registered the moment it's exported anywhere under src/ (see Auto-Discovery).

@Route('/pets')
export class PetRoute {
@Get('/:id')
async findPet(@Param('id') id: string) {
// ...
}
}

This is the hand-written path: you decide what each endpoint does, one method at a time. Auto CRUD Routes covers the alternative, generating a full CRUD endpoint from a model with no handler code at all, and Default Routes covers a library of ready-made endpoints (health, metrics, admin) you can mount as-is. This section covers how the hand-written path works in full:

  • Defining Routes@Route, the HTTP method decorators, and how a class turns into registered endpoints.
  • Request Parameters — pulling data out of the request by declaring what a handler needs, @Param, @Query, @Header, and the request body.
  • Lifecycle & Validation — the fixed pipeline every request runs through before and after your handler, and where @Validate/@Before/@After fit into it.
  • API Documentation — annotating a route so it shows up correctly in the auto-generated OpenAPI spec.