NestJS 11 · Validation, guards and interceptors
Describe and validate a request body
Use class-validator decorators on a DTO class.
export class CreateCatDto {
@IsString()
@MinLength(2)
name: string;
@IsInt()
@Min(0)
age: number;
}
Official NestJS 11 documentation
More validation, guards and interceptors commands
- Enable validation globally
- Protect routes with a guard
- Run code around handlers
- Customize error responses
- Enable CORS
- Generate OpenAPI docs
All validation, guards and interceptors commands · NestJS 11 cheatsheet