@Param()
Extracts route parameters from the request URL into a handler parameter.
Syntax
@Param(propertyOrPipe?, ...pipes) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
property | string | No | Optional name of a single route parameter to extract. |
pipes | PipeTransform[] | No | Optional pipes applied to the extracted value. |
Returns
ParameterDecorator — A decorator that binds route params to the parameter.
Examples
import { Controller, Get, Param, ParseIntPipe } from '@nestjs/common';
@Controller('cats')
export class CatsController {
@Get(':id')
findOne(@Param('id', ParseIntPipe) id: number) {
return { id };
}
@Get(':a/:b')
all(@Param() params: Record<string, string>) {
return params;
}
}
Notes
Without an argument, @Param() returns an object of all route parameters.
Combine with ParseIntPipe or ParseUUIDPipe to coerce and validate path
segments.