How do you version a public REST API?
Common strategies:
- URI path versioning:
https://api.example.com/v1/orders. Most visible and easiest to route and cache, at the cost of polluting the URL. - Query parameter:
/orders?version=2. Easy but easy to forget and awkward to cache. - Custom media type:
Accept: application/vnd.example.v2+json. Purest REST approach but harder to test and document. - Custom header:
X-Api-Version: 2. Clean URLs, but invisible and frequently missed.
For a public API, URI versioning is the pragmatic default. More important than the mechanism is the policy: prefer additive, backward-compatible changes; never change the meaning of an existing field; announce deprecations early with Deprecation and Sunset headers; keep old versions running for a defined window; and protect consumers with contract tests in CI.