@UsePipes()

Binds one or more pipes to a controller or route handler for transformation and validation.

Since NestJS 10/11 Spec ↗

Syntax

@UsePipes(...pipes: (PipeTransform | Type<PipeTransform>)[])

Parameters

NameTypeRequiredDescription
pipes PipeTransform[] No Pipe instances or classes applied to all parameters of the scope.

Returns

ClassDecorator | MethodDecorator — A decorator applied at controller or handler level.

Examples

import { Controller, Post, Body, UsePipes, ValidationPipe } from '@nestjs/common';

@Controller('cats')
export class CatsController {
  @Post()
  @UsePipes(new ValidationPipe({ whitelist: true }))
  create(@Body() dto: { name: string }) {
    return dto;
  }
}

Notes

Pipes bound with @UsePipes() apply to every argument of the scope. For application-wide validation prefer app.useGlobalPipes() in main.ts instead of repeating @UsePipes() on each handler.