Managing API Versions

1. Using URL Path Versioning

PatternProsCons
/v1/usersVisible, cacheable, easy routingURL changes break clients
/api/2023-10/usersDate-based, like StripeMany versions live

Example: Path version routing

routes:
  - paths: ["/v1/users"] service: users-v1
  - paths: ["/v2/users"] service: users-v2

2. Implementing Header-Based Versioning

HeaderExample
Acceptapplication/vnd.api+json;v=2
X-API-Version2
API-Version2023-10-15

3. Using Query Parameter Versioning

Example: Query versioning

GET /users?api-version=2 HTTP/1.1
Host: api.example.com
ProsCons
Easy to test in browserPollutes URL
Optional with defaultCache key complexity

4. Configuring Content Negotiation Versioning

AspectDetail
Media typeapplication/vnd.acme.v2+json
Quality valueq=0.9 client preference
Fallback406 Not Acceptable if no match

5. Setting Up Version Routing Rules

Example: Combined header + path

routes:
  - paths: ["/api"]
    headers: { X-API-Version: ["2"] }
    service: api-v2
  - paths: ["/api"]
    service: api-v1   # default when header absent

6. Setting Default API Versions

StrategyBehavior
Latest stableNewest production version
Pinned defaultFrozen version (e.g., v1)
Client defaultAPI key linked to version
Date pinningDefault by creation date

7. Configuring Backward Compatibility

ChangeCompatible?
Add optional fieldYes
Add new endpointYes
Remove fieldNo
Rename fieldNo (use alias)
Change typeNo
Tighten validationNo

8. Implementing Version Deprecation Policies

Deprecation Lifecycle

  1. Announce: changelog + email (T-180d)
  2. Add Deprecation and Sunset headers
  3. Log usage by client/API key
  4. Outreach top callers (T-90d)
  5. Brownouts (5min outages weekly, T-30d)
  6. Remove version, return 410 Gone

9. Managing Breaking Changes

ApproachDescription
Major version bumpv1 → v2 co-exist
Feature flagsPer-client opt-in
Field versioningfield_v2 alongside
Translator middlewarev1 requests → v2 backend

10. Implementing Version Migration Strategies

Example: Sunset header

HTTP/1.1 200 OK
Deprecation: true
Sunset: Wed, 30 Jun 2026 23:59:59 GMT
Link: <https://docs.example.com/migrate/v2>; rel="successor-version"
Warning: 299 - "v1 deprecated, migrate to v2 by 2026-06-30"