@Post()
Maps a controller method to an HTTP POST request for the given path.
Syntax
@Post(path?: string | string[]) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path | string | string[] | No | Optional route path appended to the controller prefix. |
Returns
MethodDecorator — A decorator applied to the route handler method.
Examples
import { Controller, Post, Body } from '@nestjs/common';
class CreateCatDto {
name: string;
age: number;
}
@Controller('cats')
export class CatsController {
@Post()
create(@Body() dto: CreateCatDto) {
return { created: dto.name };
}
}
Notes
POST handlers return a 201 Created status by default. Use @Body() to read
the parsed request payload, typically validated with a DTO and the global
ValidationPipe.