पाठ 20 / 27
Deprecation और Sunset Headers
Responses में deprecation का संकेत दें ताकि clients और tools उसे अपने आप पहचान सकें।
लोगों को response में ही बताएँ
Emails छूट जाते हैं, इसलिए पुराने version के हर response में भी deprecation का संकेत दें। Deprecation response header बताता है कि resource deprecated है (RFC 9745 में मानकीकृत), Sunset header (RFC 8594) वह HTTP-date देता है जिसके बाद वह काम करना बंद कर सकता है, और rel="successor-version" वाला Link header प्रतिस्थापन की ओर इशारा करता है (और rel="deprecation" दस्तावेज़ की ओर)। Clients इन्हें देखकर log या alert कर सकते हैं, और API gateways जोड़ सकते हैं कि अब भी deprecated endpoints कौन बुला रहा है। Docs, changelog और OpenAPI spec (deprecated: true) भी अपडेट करें।
पुराने versions को सम्मान से विदा करें
स्पष्ट समय-सीमा, मशीन-पठनीय संकेत और अच्छे tooling clients को घबराहट के बिना आगे बढ़ने देते हैं।
Deprecated v1 पर headers, चलाकर
मैंने यह केवल Python standard library से बने छोटे असली HTTP API पर चलाया (पूरा कोड केस स्टडी में)। v1 response में Deprecation: true, Sunset: Wed, 31 Dec 2026 23:59:59 GMT और उत्तराधिकारी के रूप में /v2/items/1 की ओर इशारा करता Link header है।
# uses srv, base and call() from the runnable demo in the case study
s, h, b = call("GET", "/v1/items/1"); print(s, b, h.get("Deprecation"), h.get("Sunset")); print(h.get("Link"))
s, h, b = call("GET", "/v2/items/1"); print(s, b, h.get("Deprecation"))
Output:
200 {'id': 1, 'name': 'Asha Rao', 'plan': 'pro'} true Wed, 31 Dec 2026 23:59:59 GMT
</v2/items/1>; rel="successor-version"
200 {'id': 1, 'first_name': 'Asha', 'last_name': 'Rao', 'plan': 'pro'} NoneSunset तक बचा समय, चलाकर
मैंने यह सादा-Python उदाहरण चलाया। 1 अक्टूबर 2026 से 31 दिसंबर 2026 के sunset तक 91 दिन हैं। याद दिलाने की योजना और नए integrations रोकने का समय तय करने के लिए ऐसी गणना उपयोग करें।
import hmac, hashlib, json, time, bisect
from datetime import datetime, timezone
sunset = datetime(2026, 12, 31, 23, 59, 59, tzinfo=timezone.utc); today = datetime(2026, 10, 1, tzinfo=timezone.utc)
print((sunset - today).days, "days left")
Output:
91 days left
त्वरित जाँच: कौन-सा header वह तारीख़ देता है जिसके बाद resource काम करना बंद कर सकता है?
- ETag
- Sunset
- Vary
- Location
Answer
Sunset — Sunset (RFC 8594) विदाई की तारीख़ बताता है; Deprecation resource को deprecated चिह्नित करता है।