Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic versioning of REST apis?

I've evaluated a number of versioning schemas for REST apis (header, url, …). So far, the most reliable approach seems to be the url option: It works with proxies, and does not rely on obscure schemas such as dates for versioning.

Now, when I look around, everybody who uses the url based approach seems to use versions such as v1, v2, and so on. Nobody uses minor versions, or even a schema such as semantic versioning.

This raises some questions:

  • When do you increase the version number of a REST api (for sure, you have more updates to it than just once in five years)?
  • If you just have a bug fix, you probably do not increase the version number, but how do you differ both versions?
  • If you use a very fine-granular approach, you end up with lots of versions you need to host in parallel. How do you handle that?

In other words: How does a company such as GitHub, e.g., make to only have v3 today (2015), when they are around in business already for 7 years now? Does that mean that they actually only changed their api two times? I can hardly believe that.

Any hints?

like image 284
Golo Roden Avatar asked Jan 12 '15 12:01

Golo Roden


People also ask

What is the most common method of versioning a REST API?

There are several methods for managing the version of your API. URI path versioning is the most common.


1 Answers

The major version number is all you need for a web service. Because your consumers are only concerned about backward incompatible changes, and (if you're following semantic versioning correctly) those will only be introduced when a new major version is released.

All other changes (including new features, bugfixes, patches etc.) should be 'safe' for your consumers. Those new features don't have to be used by your consumers, and you probably don't want to continue to run that unpatched version that contains bug X or Y any longer than necessary.

Using the complete version number in your URLs (or whatever method you use for API versioning) would actually mean that your consumers have to update the URL of your API everytime you make an update / bugfix to your API, and they would keep using an unpatched version until they do so.

This doesn't mean that you can't use semantic versioning internally, of course! Just use the first part (major version) as the version number for your API. It just doesn't make sense to include the full version number in your URL / header / other versioning system.

So to answer your question: you update your API everytime you make a new release, but you only release a new API version when you have a new major version. This way you only have to host a couple of different versions (and you can of course deprecate old versions over time).

like image 146
Nic Wortel Avatar answered Oct 26 '22 00:10

Nic Wortel