How do you configure a sunset date for a deprecated API version so clients receive a clear removal timeline?
Short answer
While Asp.Versioning itself doesn't have a built-in 'sunset date' concept, you can add a custom Sunset HTTP header (following the IETF Sunset header draft/RFC 8594 convention) via middleware or an action filter applied to deprecated version endpoints, giving clients a specific…
Advertisement
AModel answer
While Asp.Versioning itself doesn't have a built-in 'sunset date' concept, you can add a custom Sunset HTTP header (following the IETF Sunset header draft/RFC 8594 convention) via middleware or an action filter applied to deprecated version endpoints, giving clients a specific, parseable date after which the version will stop working, complementing the deprecated-versions header with concrete timing.
app.Use(async (context, next) => {
await next();
if (context.Request.Path.Value.Contains("/v1/")) {
context.Response.Headers["Sunset"] = "Sat, 31 Dec 2026 23:59:59 GMT";
}
});Real-world example
A partner API adds a Sunset header with a concrete removal date to every v1 response, giving integrators an unambiguous, machine-parseable deadline rather than a vague 'deprecated, remove eventually' signal.
Likely follow-ups
- How does the Sunset header relate to the Deprecation header from the same IETF draft?
- How would automated client tooling react to an approaching Sunset date?
Related topics