Skip to content

API versioning

Introduction

Label APIs with a version (such as v1, v2) and release a new version for incompatible changes instead of modifying the old one in place.

Why use it

  • Clients do not upgrade on your schedule: mobile users may go months without updating, and partner systems have their own release cadence.
  • Evolve with confidence: with versions, you can refactor boldly in the new one while the old one stays stable.

What counts as a breaking change

Needs a new version: removing or renaming a field, changing a field’s type or meaning, adding a required parameter, changing status-code semantics.

Does not need a new version (backward compatible): adding optional fields, adding endpoints, adding optional parameters—provided clients are “tolerant” and ignore unknown fields.

Common approaches

Approach Example Traits
Path version /v1/orders Clearest and most common; easy to cache and debug
Header version X-Api-Version: 2 Cleaner URLs, but harder to see at a glance
Query parameter /orders?api-version=2 Simple; fine as a default option

Beginners should use path versioning.

How to do it

  1. Ship with v1 from day one—bolting it on later is costly.
  2. Prefer backward-compatible evolution; open a new version only when you must.
  3. Keep at most two or three versions alive at once; more than that overwhelms the team.
  4. Retiring an old version needs a process: announce early, signal deprecation in response headers, set a cutoff date, and monitor who still uses it.
  5. Schema changes must align with API versions; see Database migrations.

Component comparison

URL path version (/v1/orders)

Built into the frameworkOpsLow

Put the version number directly in the URL path, with different versions served by different routes.

Best forMost public APIs, especially for teams without dedicated ops.

Avoid whenURL stability is critical and addresses must never change.

Pros

The version being called is obvious at a glance, which helps debugging and documentation

Caches, gateways, and logs can distinguish versions directly by path

Familiar to most developers; the most common approach

Cons

A new version changes the URL, so clients must change every request address

Strictly speaking, one resource gets multiple URLs, which does not fit REST ideals well

If each version copies the whole business code, maintenance gets messier over time

Request header version (such as X-Api-Version)

Built into the frameworkOpsLow

The URL stays the same and the version goes in a request header; the server reads it and decides which version to serve.

Best forInternal or partner APIs that have mature clients and toolchains and value URL stability.

Avoid whenEndpoints aimed at beginners or that must be tried directly in a browser.

Pros

The URL stays clean, and the version is not written into the path

The version number sits on its own and is not mixed into the resource address

The same address can evolve smoothly as the version changes

Cons

The address bar cannot open it, so debugging means sending the header by hand

Caches and gateways must distinguish versions by that request header

Docs and clients are both more likely to omit this header

Query parameter version (?api-version=2)

Built into the frameworkOpsLow

The version is passed as a parameter after the URL, and the default version is used when it is omitted.

Best forAPIs that want a smooth transition from unversioned and need a default version as a fallback.

Avoid whenYou rely on CDN or gateway caching and cannot vary the cache by parameter.

Pros

Simple to implement, and you can try it by changing the parameter in the browser

A default version can be set, so old clients still work if they omit it

The version lives in a parameter, and the URL path itself does not change

Cons

Caches easily miss it, so it must be part of the cache key

The version is mixed in with business parameters, which is less clear

Forgetting the parameter silently uses the default version, which is easy to miss

Checklist

  • APIs carry a version marker starting from v1
  • The team agrees on what counts as a breaking change
  • Clients ignore unknown fields
  • The number of coexisting versions is capped
  • There is a deprecation process: announce, signal, cutoff date, usage monitoring