Kind: Interface
Source: packages/common/interfaces/version-options.interface.ts
Part of: Common
HeaderVersioningOptions configures header-based API versioning. It identifies the HTTP header that contains the requested API version and fixes the versioning strategy to VersioningType.HEADER.
Properties
| Property | Type |
|---|---|
type | VersioningType.HEADER |
header | string |
Diagram
mermaidgraph LR Client[HTTP Client] -->|Sends version header| Request[Incoming Request] Request --> HeaderName[Configured header] HeaderName --> VersionResolver[Header Version Resolver] VersionResolver --> Route[Versioned Route Handler] Options[HeaderVersioningOptions] -->|type: VersioningType.HEADER| VersionResolver Options -->|header: string| HeaderName
Usage
tsimport { VersioningType } from '@nestjs/common';
import type { HeaderVersioningOptions } from '@nestjs/common/interfaces/version-options.interface';
const versioningOptions: HeaderVersioningOptions = {
type: VersioningType.HEADER,
header: 'X-API-Version',
};
// Example request:
// GET /users
// X-API-Version: 2
AI Coding Instructions
- Always set
typetoVersioningType.HEADER; this interface is specifically for header-based version resolution. - Provide a non-empty, stable header name such as
X-API-VersionorAPI-Version. - Ensure API clients send the configured header with every request to versioned endpoints.
- Keep the configured header name consistent across application bootstrap configuration, gateways, and API documentation.
- Do not use this interface when version information is supplied through a URI, media type, or custom extractor.
Was this page helpful?