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
| Property | Type |
|---|---|
url | string |
statusCode | HttpStatus |
Diagram
mermaidgraph 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
tsimport { 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 asFOUND,MOVED_PERMANENTLY, orTEMPORARY_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
urlto theLocationresponse header.
Was this page helpful?