What is API Versioning
API version management
API Versioning
API Versioning is the practice of managing API changes while maintaining backward compatibility for existing clients.
Versioning Strategies
| Strategy | Example | Description | |----------|---------|-------------| | URL Path | /api/v1/users | Version in URL path | | Query Parameter | /api/users?version=1 | Version in parameter | | Header | X-API-Version: 1 | Version in header | | Content Type | Accept: application/vnd.api.v1+json | Media type version |
Semantic Versioning
- Major (v1→v2) — breaking changes
- Minor (v1.1→v1.2) — new features, backward compatible
- Patch (v1.1.0→v1.1.1) — bug fixes
Best Practices
- Document all changes (changelog)
- Support at least 2 versions
- Announce deprecation in advance
- Use sunset headers
- Provide migration tools
When a New Version is Needed
- Removing fields or endpoints
- Changing response format
- Changing parameter semantics
- Changing authentication