@UseInterceptors()
Binds interceptors that wrap handler execution to transform results or add cross-cutting logic.
Syntax
@UseInterceptors(...interceptors: (NestInterceptor | Type<NestInterceptor>)[]) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
interceptors | NestInterceptor[] | No | Interceptor instances or classes applied around the handler. |
Returns
ClassDecorator | MethodDecorator — A decorator applied at controller or handler level.
Examples
import {
Controller, Get, UseInterceptors,
ClassSerializerInterceptor,
} from '@nestjs/common';
@Controller('users')
@UseInterceptors(ClassSerializerInterceptor)
export class UsersController {
@Get()
find() {
return { id: 1, name: 'Ada' };
}
}
Notes
Interceptors can run logic before and after the handler using RxJS
operators on the call handler stream. Common uses include response
shaping, caching, logging, and timeouts.