Skip to content

UriVersioningOptions

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/version-options.interface.ts

Part of: Common

UriVersioningOptions configures URI-based API versioning. It requires the versioning strategy to be VersioningType.URI and optionally customizes—or disables—the URI prefix used before the version segment.

Properties

PropertyType
typeVersioningType.URI
prefix`string

Diagram

mermaid
graph LR
  A[Application Versioning Configuration] --> B[UriVersioningOptions]
  B --> C[type: VersioningType.URI]
  B --> D[prefix: string | false]
  C --> E[Version read from request URI]
  D --> F[Generated route path]
  E --> F

Usage

ts
import { VersioningType } from '@nestjs/common';
import type { UriVersioningOptions } from '@nestjs/common';

const versioningOptions: UriVersioningOptions = {
  type: VersioningType.URI,
  prefix: 'v',
};

// Produces routes such as: /v1/users
app.enableVersioning(versioningOptions);

AI Coding Instructions

  • Always set type to VersioningType.URI; this interface is only valid for URI-based versioning.
  • Use a string prefix such as 'v' when versioned routes should look like /v1/resource.
  • Set prefix: false when the version should appear without a prefix, such as /1/resource.
  • Pass these options to the application's versioning configuration, typically through app.enableVersioning().
  • Keep the configured prefix consistent with API gateway routes, documentation, and client URL construction.

How it works

UriVersioningOptions is a public TypeScript interface for selecting URI-based API versioning. Its required discriminant is type: VersioningType.URI; its only URI-specific setting is the optional prefix, typed as string | false. packages/common/interfaces/version-options.interface.ts:45-58 VersioningType.URI is the URI member of the versioning-type enum. packages/common/enums/version-type.enum.ts:4-8

No validation, normalization, or explicit error handling for prefix appears in the URI-prefix selection code; a defined string is returned as-is. packages/core/router/route-path-factory.ts:86-96

Was this page helpful?

Download as PDF
UriVersioningOptions — NestJS head-to-head