Versioning

But if a breaking change cannot be avoided, then we must abide by semantic versioning (semver) and increase the major version of our API. But where do we store the version data? There are generally two approaches:

  • In the URL (for instance, /v2/users): This is by far the easiest to explain and implement, but it's semantically incorrect. This is because URLs should be used to locate a resource; if we add versioning information to the URL, it'd imply that the resource itself is versioned, not the API.
  • As part of the Accept header (for instance, Accept: application/vnd.hobnob.api.v2+json): The vnd prefix in the MIME type denotes that this is a vendor-specific MIME type; here, we are using it to specify the API version we want. The ...

Get Building Enterprise JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.