Skip to content

HeaderVersioningOptions

reference
1 min readUpdated

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

PropertyType
typeVersioningType.HEADER
headerstring

Diagram

mermaid
graph 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

ts
import { 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 type to VersioningType.HEADER; this interface is specifically for header-based version resolution.
  • Provide a non-empty, stable header name such as X-API-Version or API-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?

Download as PDF
HeaderVersioningOptions — NestJS head-to-head