Kind: Interface
Source: packages/common/interfaces/version-options.interface.ts
Part of: Common
MediaTypeVersioningOptions configures media type–based API versioning. It identifies the versioning strategy with type: VersioningType.MEDIA_TYPE and defines the media type parameter key used to extract the requested API version from request headers.
Properties
| Property | Type |
|---|---|
type | VersioningType.MEDIA_TYPE |
key | string |
Diagram
mermaidgraph LR Client[HTTP Client] --> Header[Accept / Content-Type Header] Header --> Key[Media Type Parameter Key] Key --> Version[Requested API Version] Version --> Router[Versioned Route Handler] Options[MediaTypeVersioningOptions] --> Type["type: VersioningType.MEDIA_TYPE"] Options --> KeyName["key: string"] KeyName --> Key
Usage
tsimport { VersioningType } from '@nestjs/common';
import type { MediaTypeVersioningOptions } from '@nestjs/common';
const versioningOptions: MediaTypeVersioningOptions = {
type: VersioningType.MEDIA_TYPE,
key: 'v',
};
// Example request header:
// Accept: application/json;v=2
//
// The application resolves this request to API version "2".
AI Coding Instructions
- Always set
typetoVersioningType.MEDIA_TYPE; this interface is specifically for media type versioning. - Choose a stable, short
keysuch asvand keep it consistent across clients and API documentation. - Ensure clients send the configured parameter in an appropriate media type header, such as
Accept: application/json;v=2. - Use this option with the framework's global versioning configuration rather than implementing version parsing manually.
Was this page helpful?