Definition
Deprecation is the formal announcement that an API feature, endpoint, parameter, or version is obsolete and will be removed in a future release. During the deprecation period, the feature remains functional but is discouraged from use. This allows API consumers to migrate to alternative solutions without immediate disruption.
Deprecation is not removal. It’s a transitional state between active support and sunset (final retirement). Effective deprecation includes:
- Clear announcement with timeline
- Migration path to replacement functionality
- HTTP headers signaling deprecation status
- Documentation updates
- Proactive communication to affected consumers
Example
GitHub API v3 Deprecation:
GitHub deprecated several REST API v3 endpoints in favor of GraphQL:
GET /repos/:owner/:repo/events
HTTP/1.1 200 OK
Deprecation: true
Sunset: Sat, 31 Dec 2024 23:59:59 GMT
Link: <https://docs.github.com/graphql>; rel="alternate"
Link: <https://docs.github.com/rest/migration>; rel="deprecation"
[
{"id": "12345", "type": "PushEvent"}
]
Deprecation strategy:
- Announcement: 18 months before sunset
- Headers: Deprecation + Sunset dates in every response
- Docs: Migration guide with GraphQL equivalents
- Monitoring: Dashboard showing deprecated endpoint usage
- Email: Notifications to API consumers still using deprecated endpoints
Code Example
# Deprecated endpoint response
GET /api/v1/users HTTP/1.1
Host: api.example.com
Authorization: Bearer <token>
HTTP/1.1 200 OK
Deprecation: true
Sunset: Wed, 01 Jan 2025 00:00:00 GMT
Link: <https://api.example.com/v2/users>; rel="successor-version"
Link: <https://docs.example.com/migration/v1-to-v2>; rel="deprecation"
Warning: 299 - "API v1 is deprecated. Migrate to v2 by 2025-01-01"
X-API-Deprecation-Info: https://status.example.com/deprecations/v1
Content-Type: application/json
{
"data": [
{"id": 1, "name": "Alice"}
],
"_deprecation": {
"deprecated": true,
"sunset_date": "2025-01-01",
"replacement": "https://api.example.com/v2/users",
"migration_guide": "https://docs.example.com/migration/v1-to-v2",
"reason": "v2 introduces pagination and filtering"
}
}
Client-side detection:
async function fetchUsers() {
const response = await fetch('https://api.example.com/v1/users', {
headers: {
'Authorization': 'Bearer <token>'
}
});
// Check deprecation headers
if (response.headers.get('Deprecation')) {
const sunset = response.headers.get('Sunset');
const migrationGuide = response.headers.get('Link')
?.match(/<([^>]+)>; rel="deprecation"/)?.[1];
console.warn(`API is deprecated. Sunset: ${sunset}`);
console.warn(`Migration guide: ${migrationGuide}`);
// Log to monitoring system
logger.warn('DEPRECATED_API_USAGE', {
endpoint: '/v1/users',
sunset: sunset,
migrationGuide: migrationGuide
});
}
return response.json();
}
Diagram
graph LR
A[v1 Active] -->|New feature requires
breaking change| B[v2 Development]
B -->|Release v2| C[v2 Active]
C -->|Announce deprecation| D[v1 Deprecated]
D -->|Add headers| E[Deprecation: true
Sunset: date]
D -->|Notify users| F[Email campaigns
Dashboard warnings]
D -->|6-18 months| G[Migration period]
G -->|Monitor usage| H[Track v1 traffic]
H -->|Usage drops| I[Extend deadline?]
I -->|No| J[v1 Sunset]
I -->|Yes| K[Extend 3-6 months]
K --> G
J -->|Remove endpoints| L[v1 Retired
301/410 responses]
style A fill:#90EE90
style C fill:#90EE90
style D fill:#FFD700
style G fill:#FFD700
style J fill:#FF6B6B
style L fill:#FF6B6B
Best Practices
1. Use Standard HTTP Headers
Implement Deprecation: true and Sunset headers (RFC 8594) in all responses from deprecated endpoints.
2. Provide Clear Timeline Announce deprecation with a specific sunset date. Minimum 12 months for public APIs, 6 months for internal APIs.
3. Document Migration Paths Every deprecated feature must have a documented replacement with code examples showing before/after migration.
4. Monitor Usage Proactively Track which clients still use deprecated endpoints. Contact high-volume users directly.
5. Add Deprecation to API Spec
Mark endpoints as deprecated: true in OpenAPI specs. Automated tools can detect usage at build time.
6. Implement Multiple Notification Channels
- HTTP headers (runtime detection)
- Email to registered API consumers
- In-app notifications (if you have a dashboard)
- Changelog and blog posts
- Status page announcements
7. Gradual Degradation (Optional) Optionally reduce rate limits for deprecated endpoints to encourage migration (e.g., 1000 req/min → 100 req/min).
8. Never Extend Deadlines Last-Minute If you must extend, announce it at least 3 months before the original sunset date.
Common Mistakes
1. Deprecating Without Replacement Removing functionality without providing an alternative forces consumers to abandon features or switch providers.
2. Insufficient Notice Period Deprecating with only 1-3 months notice doesn’t give enterprise clients time to plan sprints and deploy changes.
3. Silent Deprecation Only updating documentation without HTTP headers or email notifications means many consumers won’t notice until it’s too late.
4. No Tracking of Deprecated Usage Sunsetting an endpoint without checking usage metrics can break critical integrations still in active use.
5. Removing Deprecated Features Too Early Some clients legitimately need more time. Monitor usage and extend deadlines if a significant portion still depends on deprecated features.
6. Inconsistent Deprecation Policies Different teams using different timelines creates confusion. Standardize policies across the organization.
7. Breaking Backward Compatibility During Deprecation Deprecated features should remain fully functional until sunset. Don’t introduce bugs or reduce functionality during the deprecation period.