Video in progress
What ways are there to version a REST API?
The most common are in the URL (/api/v1/orders), in a header (X-API-Version: 2), or in the media type (Accept: application/vnd.shop.v2+json). The URL approach is the simplest and most visible, so it's the one chosen most often in practice.
📖 Answer
GET /api/v1/orders/42 # URL path
GET /api/orders/42?version=2 # query parameter
GET /api/orders/42
X-API-Version: 2 # custom header
Accept: application/vnd.shop.v2+json # media type
The URL approach: it's visible in the browser, in logs and in gateway routes, and caching is easy. The drawback is the theoretical objection "one resource, two URLs".
Header and media type: the URL stays clean, but debugging is less convenient and you have to set the Vary header correctly in caches.
Spring Framework 7 / Spring Boot 4 added built-in support for API versioning; in Spring Boot 3 people usually do it by hand with the URL or @RequestMapping(headers = ...).
More important than the method is bumping the version rarely. Every new version commits you to supporting the old one. Most changes can be made in a backward compatible way, and a version is needed only for a truly breaking change.
Sign up to mark studied questions and save your progress.