LearnFrenzy
Sign in Take a free test

Versioning, Webhooks and Alternatives · Lesson 23 of 30

REST API Versioning and Deprecation

4 min read Updated Nov 8, 2026 Saurabh Samir

Once other teams, partners or mobile apps depend on your API, you can't change it freely – an app installed two years ago still calls it. Good API teams avoid breaking changes wherever possible, version when they must, and retire old versions with clear, machine-readable warnings. This lesson covers all three.

In this lesson

  • Breaking vs non-breaking changes
  • URL, header and media-type versioning
  • Two versions side by side – running
  • Deprecation and Sunset headers

What breaks clients?

Usually safe (non-breaking)Breaking
adding a new endpointremoving or renaming an endpoint or field
adding an optional request fieldmaking an optional field required
adding a response fieldchanging a field's type or format (number → string, date format)
adding a new enum value – if clients were told to expect themchanging status codes or error formats
relaxing validationtightening validation; changing default behaviour

Design for evolution from day one: clients should ignore unknown fields, and your docs should say new fields and enum values may appear. Then most changes never need a new version.

Versioning styles

StyleExamplePros / cons
URL path/api/v2/ordersobvious, easy to route, cache and test; most common (Twitter/X, Razorpay)
HeaderApi-Version: 2026-11-01clean URLs; date-based versions per account (Stripe); harder to try in a browser
Media typeAccept: application/vnd.learnfrenzy.v2+jsonmost "RESTful" in theory (GitHub); least convenient
Query?api-version=2simple (Azure); easy to forget

Two versions side by side

Version 2 splits name into first and last names – a breaking change. Both versions share the same data and business logic; only the representation differs:

// server.js
import express from 'express';

const app = express();
const customers = [{ id: 'c1', firstName: 'Asha', lastName: 'Verma', email: 'asha@example.com' }];

// v1 – deprecated: still served, but announces its retirement
const v1 = express.Router();
v1.use((req, res, next) => {
  res.set({
    Deprecation: '@1767225600',                              // deprecated since 2026-01-01 (RFC 9745)
    Sunset: 'Wed, 30 Jun 2027 00:00:00 GMT',                 // will stop working on this date (RFC 8594)
    Link: '<https://api.learnfrenzy.com/docs/migrate-v2>; rel="deprecation"',
  });
  next();
});
v1.get('/customers/:id', (req, res) => {
  const c = customers.find((x) => x.id === req.params.id);
  res.json({ id: c.id, name: `${c.firstName} ${c.lastName}`, email: c.email });
});

// v2 – current
const v2 = express.Router();
v2.get('/customers/:id', (req, res) => {
  const c = customers.find((x) => x.id === req.params.id);
  res.json({ id: c.id, firstName: c.firstName, lastName: c.lastName, email: c.email });
});

app.use('/api/v1', v1);
app.use('/api/v2', v2);
app.listen(process.env.PORT ?? 3000);

Real responses

$ curl http://localhost:3000/api/v1/customers/c1
HTTP/1.1 200 OK
Deprecation: @1767225600
Sunset: Wed, 30 Jun 2027 00:00:00 GMT
Link: <https://api.learnfrenzy.com/docs/migrate-v2>; rel="deprecation"
Content-Type: application/json; charset=utf-8

{
  "id": "c1",
  "name": "Asha Verma",
  "email": "asha@example.com"
}

$ curl http://localhost:3000/api/v2/customers/c1
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
  "id": "c1",
  "firstName": "Asha",
  "lastName": "Verma",
  "email": "asha@example.com"
}
  • Old clients keep working on v1, but every response tells them – and their monitoring – that v1 is deprecated, when it will disappear, and where the migration guide is.
  • Keep version-specific code thin: shared services, different serialisers. Maintaining two full codebases doesn't scale.

Retiring a version

A respectful deprecation timeline

  1. Announcerelease v2, publish a migration guide, add Deprecation headers to v1
  2. Measurelog which API keys still call v1; contact them directly
  3. Remindemails, dashboard banners; brownouts (short planned outages) to surface forgotten callers
  4. Sunsetafter 6–12 months, v1 returns 410 Gone with a link to the docs

Version rarely, evolve often

Every version you run is code to maintain, test and secure (forgotten old versions are OWASP API9). Prefer additive changes; when you must break something, batch several breaking changes into one new version.

Practice

Try it yourself

  1. Classify each change: (a) add phone to customer responses, (b) rename email to emailAddress, (c) return amounts in paise instead of rupees, (d) add GET /api/v2/customers/{id}/orders.

    Show answer

    (a) non-breaking, (b) breaking, (c) breaking – same field, different meaning, the worst kind, (d) non-breaking.

Quick check

Is adding a response field a breaking change?

Normally no – clients should ignore unknown fields.

Which header announces the shutdown date?

Sunset.

What should a retired version return?

410 Gone with a link to migration docs.

Summary

  • Avoid breaking changes; design clients to ignore unknown fields.
  • Version in the URL (most common) or a header; share logic, vary representations.
  • Deprecate with Deprecation, Sunset and Link headers, measure usage, then return 410.

Finished this lesson?

Mark it complete to track your progress, then carry on with the next lesson.

Next lesson

Search LearnFrenzy

Esc

Quick links