Lesson 5 / 33

Routes & Decorators Deep Dive

Master parameter decorators, response handling, and status codes.

Decorators: Param, Body, Query

Extract different parts of a request with decorator arguments.

@Post(':id')
update(
  @Param('id') id: string,
  @Body() updateDto: UpdateUserDto,
  @Query('notify') notify?: boolean
) {
  return this.usersService.update(id, updateDto, notify);
}

Status codes & headers

Use @HttpCode() to override the default status (201 for POST), and @Header() to set response headers.

@Post()
@HttpCode(202)
@Header('X-Custom', 'value')
create(@Body() dto: CreateUserDto) {
  return this.usersService.create(dto);
}

Nested routes & wildcards

Stack controllers and paths—e.g. @Controller('api/users') + @Get(':id/posts') → /api/users/:id/posts.