पाठ 5 / 33

Routes और Decorators गहराई में

Parameter decorators, response handling और status codes master करें।

Decorators: Param, Body, Query

Decorator arguments के साथ request के विभिन्न भागों को extract करें।

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

Status codes और headers

Default status को override करने के लिए @HttpCode() उपयोग करें (POST के लिए 201), और response headers सेट करने के लिए @Header() उपयोग करें।

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

Nested routes और wildcards

Controllers और paths को stack करें—उदा. @Controller('api/users') + @Get(':id/posts') → /api/users/:id/posts।