Rest – Versioning REST APIs. Each API has its own version

api-designengineeringenterprise-architecturerestversioning

It's very common to specify the version of REST APIs in the URL, specifically at the beginning of path, i.e. something like:

POST /api/v1/accounts
GET /api/v1/accounts/details

However, I haven't seen any design where the version is associated with each API. In other words, we maintain the version of each API separately. i.e.:

POST /api/accounts/v2
GET /api/accounts/details/v3

Using this approach we increment the API version of the specific API when breaking change is needed, no need to increment the version of the whole APIs.

What are the drawbacks of using this style instead of the common style?

Best Answer

What you call single REST APIs might be called REST API's particular set of resources or resources. You also could look at it as REST API's functionalities. Such as any kind of software, the whole package is versioned/updated, not single functionalities or resources.

Your question would make sense in the context where the REST API package's resources are modular and so potentially developed and versioned separately.

Then, as far as I see, the main cons of your proposed resource locator naming convention are:

  • For the API user, it would result in much more complex resource locators, less predictable, less memorable and less stable.
  • For the module developer(s), it's now more work to have to deal with this versioning in their own resource locator.
  • Changes in resource locators become much more frequent, as much as there are multiple modules updating so the cons above are exponential...

When building an API, one of your main objectives is making it easy to use...

You might find a better way to introduce a breaking change or even versioning the REST API with maybe a HTTP header?

To know a little more about HTTP headers approach, see other answers below and: https://www.troyhunt.com/your-api-versioning-is-wrong-which-is/