Deprecating an API endpoint: test the Deprecation and Sunset headers

Removing an endpoint is easy. Making sure nobody still depends on it is the hard part. The polite way is to announce it in the responses themselves, months ahead, with standard headers that client libraries and gateways can read.

The headers

HTTP
HTTP/1.1 200 OK
Deprecation: @1764547200
Sunset: Wed, 30 Jun 2027 00:00:00 GMT
Link: <https://developer.example.com/migrate/orders-v2>; rel="deprecation", <https://api.example.com/v2/orders>; rel="successor-version"
  • Deprecation is a date as a Unix timestamp with @ in front: from then on, the endpoint is deprecated. (Older drafts used Deprecation: true; you will still see it.)
  • Sunset is an HTTP date: after it, the endpoint may stop answering.
  • Link carries the human-readable explanation and the replacement.

Sunset should come after Deprecation, and the gap should match what you promised clients, often 6 or 12 months.

A folder for deprecated endpoints

Move the requests for endpoints you are retiring into a Deprecated folder, and give the folder assertions on its Tests tab:

SourcePathOperatorExpected
HeaderDeprecationexists
HeaderSunsetexists
HeaderLinkcontainsrel="deprecation"

They apply to every request in the folder. When someone forgets to add the middleware to one of the old routes, its request fails.

Check the dates make sense

JavaScript
const sunset = Date.parse(pm.response.headers.get('Sunset'));
const dep = pm.response.headers.get('Deprecation') || '';
const depTime = dep.startsWith('@') ? Number(dep.slice(1)) * 1000 : NaN;

pm.test('Sunset is a valid date in the future', () => {
  pm.expect(Number.isNaN(sunset)).to.equal(false);
  pm.expect(sunset).to.be.above(Date.now());
});

pm.test('at least 6 months between deprecation and sunset', () => {
  pm.expect(Number.isNaN(depTime)).to.equal(false);
  pm.expect(sunset - depTime).to.be.at.least(182 * 24 * 3600 * 1000);
});

The "in the future" check turns into a reminder: the day it fails, the sunset date has passed and the endpoint should be gone, or the date should move.

The replacement works

Every deprecated request should have a twin that calls the successor. Keep both in the collection until the sunset, and run both. A migration guide that points at a v2 endpoint with a different behaviour is how migrations stall.

JavaScript
// On the v2 request: the same order through the new endpoint
pm.test('v2 returns the same order', () => {
  pm.expect(pm.response.json().id).to.equal(pm.environment.get('orderId'));
});

The current endpoints are not deprecated

The opposite mistake happens too: a shared middleware adds Deprecation to everything. Put this on the collection or on the folders with current endpoints:

SourcePathOperatorExpected
HeaderDeprecationdoes not exist

Using this from the client side

If your team calls other teams' APIs, add a collection-level post-response script that warns when any response carries a Sunset header:

JavaScript
const sunset = pm.response.headers.get('Sunset');
if (sunset) {
  console.warn(`${pm.request.method} ${pm.request.url.getPath()} is deprecated, sunset ${sunset}`);
}

The warnings show up in the diagnostics console in the app and with --verbose in the CLI, so a scheduled run tells you about a retirement before the endpoint disappears.