🦅 NestJS Beginner

What is the ValidationPipe in NestJS?

Answer

The ValidationPipe is a built-in NestJS pipe that integrates with the class-validator and class-transformer libraries to automatically validate incoming request data against DTO classes. Apply globally in main.ts: app.useGlobalPipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, transform: true }));. whitelist: true strips properties not in the DTO. forbidNonWhitelisted: true throws a 400 error if extra properties are sent. transform: true automatically transforms payloads to DTO instances and converts route parameters to the declared type. Without the ValidationPipe, you must manually validate every incoming request.