API versioning

Overview#

API versioning is the methodology of naming and deploying Application Programming Interface versions.

What you are creating is not a new version of the API, but a new system with a new brand. On the Web, we call that a new website. Websites don’t come with version numbers attached because they never need to. Neither should a RESTful API. A RESTful API is just a website for clients with a limited vocabulary.
— Roy Fielding

The various versioning camps#

Right, so how hard can this versioning business be? I mean it should be a simple exercise, right? The problem is that it gets very philosophical, but rather than get bogged down in that for now, let me outline the three common schools of thought in terms of how they’re practically implemented:

There have been many, many things written on this and I’m going to link to them at the end of the post, but here’s the abridged version:

Best Practices for API versioning#

Our suggestion is that you keep the url to the API consistent and that it represent the "current" version.

Similar to:

https://willeke.com/api/app1/method1

We also suggest the Accept header contain the with the current version and document in APIs use Content negotiation. This will permit consistent access the your APIs without changing their applications. Clients should perform Content negotiation as required.

Accept header Example to:

GET /api/app1/ HTTP/1.1
Accept: application/willeke.com.app1+json;version=2.1”,“application/json; profile=application/willeke.com.app1 version=2.1"

You might also make versions available via versioned URLs

https://willeke.com/api/app1/v2.1/method1/1234
https://willeke.com/api/app1/v2.0/method1/1234
https://willeke.com/api/app1/v2/method1/1234
https://willeke.com/api/app1/v1.1/method1/1234
https://willeke.com/api/app1/v1/method1/1234

Handling "outdated" and "updated" APIs [1]#

There are at least two redirection HTTP Status Codes that are appropriate for API versioning scenarios:

More Information#

There might be more information for this subject on one of the following: