NestJS 11 · Controllers, providers and modules
Write a controller
Decorators map methods to routes. Pipes such as ParseIntPipe convert and validate parameters.
@Controller('cats')
export class CatsController {
constructor(private readonly cats: CatsService) {}
@Get()
findAll(@Query('limit') limit?: string) {
return this.cats.findAll(limit ? +limit : undefined);
}
@Get(':id')
findOne(@Param('id', ParseIntPipe) id: number) {
return this.cats.findOne(id);
}
@Post()
@HttpCode(201)
create(@Body() dto: CreateCatDto) {
return this.cats.create(dto);
}
}
Official NestJS 11 documentation
More controllers, providers and modules commands
- Write a provider (service)
- Wire things together in a module
- Provide a value or factory
- Load configuration
All controllers, providers and modules commands · NestJS 11 cheatsheet