Skip to content

ResponseDecoratorOptions

reference
1 min readUpdated

Kind: Interface

Source: packages/common/decorators/http/route-params.decorator.ts

Part of: Common

The @Response()/@Res parameter decorator options.

ResponseDecoratorOptions configures the behavior of NestJS's @Response() (or @Res()) parameter decorator. Its passthrough option determines whether Nest continues its normal response-processing pipeline after injecting the underlying platform response object into a controller handler.

Properties

PropertyType
passthroughboolean

Diagram

mermaid
graph LR
  A[Incoming HTTP Request] --> B[Controller Handler]
  B --> C["@Res() / @Response()"]
  C --> D[ResponseDecoratorOptions]
  D --> E{passthrough?}
  E -->|false or omitted| F[Handler manages response manually]
  E -->|true| G[Nest processes returned value]
  G --> H[HTTP Response]
  F --> H

Usage

ts
import { Controller, Get, Res } from '@nestjs/common';
import type { Response } from 'express';

@Controller('health')
export class HealthController {
  @Get()
  check(@Res({ passthrough: true }) response: Response) {
    response.setHeader('X-Service-Status', 'healthy');

    // Nest still serializes and sends this returned value.
    return { status: 'ok' };
  }
}

AI Coding Instructions

  • Use @Res({ passthrough: true }) when a handler needs to set headers, cookies, or status codes while still returning a value for Nest to serialize.
  • Without passthrough: true, the handler is responsible for sending the response, such as with response.json() or response.send().
  • Avoid mixing manual response sending with returned response data when passthrough is enabled; this can cause duplicate-response errors.
  • Keep response types aligned with the configured HTTP platform, such as Express Response or Fastify FastifyReply.

Was this page helpful?

Download as PDF
ResponseDecoratorOptions — NestJS head-to-head