What Is API Versioning? Backward-Compatible API Design
Does adding new fields break existing clients? Unsure when to remove old endpoints? API versioning lets you evolve your API without breaking consumers.
Versioning Strategies
1. URI Versioning (Recommended)
GET /api/v1/users/42
GET /api/v2/users/42
2. Header Versioning
Accept: application/vnd.myapp.v2+json
3. Query Parameter
GET /api/users/42?version=2
Breaking vs Non-Breaking Changes
Breaking: Adding required fields, removing fields, changing response structure Non-Breaking: Adding optional fields, new endpoints, new optional parameters
Deprecation Strategy
- Announce deprecation | 2. Add Sunset header | 3. Give 6-12 month transition | 4. Monitor usage | 5. Remove when usage near zero
Best Practices
- Avoid versioning when possible — Prefer backward-compatible changes
- URI versioning for clarity
- Maximum 2 active versions
- Deprecation policy — Minimum 6 months
- Keep API docs current — Swagger/OpenAPI
Conclusion
API versioning lets you evolve without breaking clients. URI versioning is the most common approach, but the best strategy minimizes the need for versioning through backward-compatible design.
Learn API design on LabLudus.