01 / 04

How does API versioning work in NestJS?

NestJS supports three versioning strategies: URI (/v1/users), HEADER, and MEDIA_TYPE. Enable it with app.enableVersioning({ type: VersioningType.URI }), then annotate controllers or individual routes with @Version('1').

Three versioning strategies:
  1. 1

    URI versioning — version appears in the URL path: /v1/users.

  2. 2

    Header versioning — version is passed in a custom request header.

  3. 3

    Media type versioning — version is embedded in the Accept header.

Enabling URI versioning