Skip to main content

API Versioning

APIs evolve. Prism supports three versioning strategies — URL prefix, header, and query parameter — so you can introduce breaking changes without breaking existing clients.

Quick Start

URL-Based Versioning

Versioning Strategies

The version prefix is stripped from the path — your route handler sees /users, not /v1/users.

Version Format

Parsing Versions
Versions are Comparablev1 < v2 < v2.1.

Accessing the Version

In Route Handlers

Versioned Router

For cleaner separation, use PrismVersionedRouter:
Version-Specific Routes

Unsupported Version Response

When a client requests an unsupported version, the middleware returns a 400:
400 Response

URL Prefix Path Stripping

With .urlPrefix, the version prefix is removed. The original versioned path is stored in userInfo["versionedPath"]:
Path Handling
URL prefix versioning is the most common approach for public APIs — it’s explicit, easy to document, and works with any HTTP client. Use header versioning for internal APIs where you want clean URLs and controlled clients.
Set defaultVersion to your oldest supported version, not the latest. This way, existing clients that don’t send a version continue to work. New clients explicitly opt in to newer versions.