Skip to content

MediaTypeVersioningOptions

reference
1 min readUpdated

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

PropertyType
typeVersioningType.MEDIA_TYPE
keystring

Diagram

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

ts
import { 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 type to VersioningType.MEDIA_TYPE; this interface is specifically for media type versioning.
  • Choose a stable, short key such as v and 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?

Download as PDF
MediaTypeVersioningOptions — NestJS head-to-head