Skip to the workspace
Pebellslearn by building
Designing RESTful APIs  ›  Lesson

Versioning Strategies

Versioning Strategies 14 minAdditive changes are safe within a version, while removing, renaming or changing the meaning of anything needs a new version, which can live in the path, a query parameter or a header.

api design / Versioning Strategies

Explore each scene at your own pace.

01 · The rule

The rule

Versioning Strategies

BookNook wants to split a book's author string into a list of authors, since many books have several. Thousands of installed phone apps still read author. Change it in place and they break tonight. Versioning is how an API grows without pulling the floor out from under the people already standing on it.

The rule

Add freely; never remove or rename without a new version.

First, sort every change into one of two kinds:

  • Non-breaking (safe in the current version): adding a new endpoint, adding an optional request field, adding a new field to a response. Well-written clients ignore fields they do not know.
  • Breaking (needs a new version): removing or renaming a field, changing a field's type or meaning, making an optional field required, changing a URL or status code that callers rely on.

When a break is truly needed, there are three common places to put the version:

GET /v2/books/42                                     URI path
GET /books/42?version=2                              query parameter
GET /books/42   Accept: application/vnd.booknook.v2+json   header / media type
  • URI path (/v1, /v2): the most visible and easiest to test, route and cache. BookNook uses it.
  • Query parameter: easy to add, but easy to forget, and it muddles the "which thing" of the path.
  • Header or media type: keeps URLs clean and fits content negotiation, but is invisible in a browser bar and easy to miss in logs.

Whichever you choose, run old and new side by side, and deprecate the old one politely: announce a date, send a Deprecation or Sunset header on old responses, and watch traffic until it falls away.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.