Routing
Routing in Nova is defined through HTTP method decorators applied to controller methods. Each decorator maps a method to a specific HTTP verb and path.
HTTP Method Decorators
| Decorator | HTTP Method | Example |
|---|---|---|
@Get(path?, options?) | GET | @Get('/list') |
@Post(path?, options?) | POST | @Post() |
@Put(path?, options?) | PUT | @Put('/:id') |
@Patch(path?, options?) | PATCH | @Patch('/:id') |
@Delet(path?, options?) | DELETE | @Delet('/:id') |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Optional | Route path relative to the controller prefix. Defaults to "". |
options | RouteOptions | Optional | Extra route configuration (see below). |
RouteOptions
Options you can pass to any HTTP method decorator for additional route configuration:
| Property | Type | Required | Description |
|---|---|---|---|
responseModel | ZodType | Optional | Zod schema for validating and typing the response. |
statusCode | number | Optional | HTTP status code for the response. Defaults to 200. |
tags | string[] | Optional | OpenAPI tags for grouping in Swagger. |
summary | string | Optional | Summary shown in Swagger docs. |
description | string | Optional | Detailed description in Swagger. |
includeInSchema | boolean | Optional | If true, this route will be included in the OpenAPI schema. Defaults to false. |
Usage with RouteOptions
user.controller.ts TypeScript
import { Controller, Get, Post, StatusHTTP } from '@abrahambass/nova';
import { z } from 'zod';
const UserResponse = z.object({
id: z.number(),
name: z.string(),
email: z.string(),
});
@Controller('/users')
class UserController {
@Get('', {
responseModel: z.array(UserResponse),
summary: 'List all users',
includeInSchema: true,
})
async findAll() {
return [{ id: 1, name: 'John', email: 'john@mail.com' }];
}
@Post('', {
statusCode: StatusHTTP.CREATED, // 201
includeInSchema: true,
})
async create() { ... }
} Route Paths
The final URL is formed by joining the controller prefix with the method's path:
Examples text
// @Controller('/api/v1/users')
@Get() → GET /api/v1/users
@Get('/:id') → GET /api/v1/users/:id
@Post() → POST /api/v1/users
@Put('/:id') → PUT /api/v1/users/:id
@Delet('/:id') → DELETE /api/v1/users/:id 💡 Path Normalization
Nova automatically normalizes paths: removes duplicate slashes, ensures a leading slash, and removes trailing slashes.