Skip to content

HttpRedirectResponse

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/http/http-redirect-response.interface.ts

Part of: Common

HttpRedirectResponse defines the data required to represent an HTTP redirect response. It pairs a destination url with an HTTP redirect statusCode, allowing HTTP adapters or controllers to consistently construct redirect behavior.

Properties

PropertyType
urlstring
statusCodeHttpStatus

Diagram

mermaid
graph LR
  A[Controller or Route Handler] --> B[HttpRedirectResponse]
  B --> C[url: string]
  B --> D[statusCode: HttpStatus]
  B --> E[HTTP Adapter]
  E --> F[Redirect Response]

Usage

ts
import { HttpStatus } from '@nestjs/common';
import { HttpRedirectResponse } from './http-redirect-response.interface';

function createLoginRedirect(): HttpRedirectResponse {
  return {
    url: '/login',
    statusCode: HttpStatus.FOUND,
  };
}

const redirect = createLoginRedirect();

// HTTP adapter uses:
// Location: /login
// Status: 302 Found

AI Coding Instructions

  • Always provide a valid redirect target in url, such as a relative application path or a fully qualified URL.
  • Use an appropriate redirect status from HttpStatus, such as FOUND, MOVED_PERMANENTLY, or TEMPORARY_REDIRECT.
  • Keep this interface limited to redirect metadata; response headers and body handling belong to the HTTP adapter layer.
  • Ensure controller and adapter implementations consistently map url to the Location response header.

Was this page helpful?

Download as PDF
HttpRedirectResponse — NestJS head-to-head