Track 06 · Lesson 5 of 8APIs and servers

Track 06 · APIs and servers

Versioning and breaking changes

Lesson 5 of 8· 6 min

Once someone else’s code depends on your API, every change is a negotiation. Adding things is almost always safe; renaming, removing or retyping things breaks clients you can’t update.

Change the response

Toggle changes, then ship them as /v2

GET /v1/orders/41

{
  "id": 41,
  "total": 30,
  "status": "paid",
  "customer": {
    "name": "Ana"
  }
}
  • Your website

    Working

    Deployed together with the API

  • Mobile app v2.3

    Working

    People update apps slowly; months, not minutes

  • A partner’s integration

    Working

    Someone else’s code you can’t change

Nothing broke. Additive changes are the ones you can ship any day.

Safe and breaking#

Safe (additive): new endpoints, new optional fields in requests, new fields in responses. Breaking: renaming or removing a field, changing its type, making an optional field required, changing what an error code means. New values in an enum are a grey zone: say upfront that clients must handle unknown values.

Versions buy time#

When a breaking change is worth it, ship it beside the old one: a new path (/v2/orders), a header, or a dated version. Keep the old version running, announce a sunset date, send Deprecation and Sunset headers on old responses, and watch your logs until nobody calls it.

Be liberal in what you accept#

Clients should ignore fields they don’t recognise and cope with new enum values; servers should accept old request shapes for as long as they promised. That’s what lets both sides change independently.

Check yourself

Which change is safe to ship to an API used by an old mobile app?