This document describes the API versioning strategy for the Mobile Money application. Versioning allows the API to evolve and introduce breaking changes without affecting existing clients.
-
v1 - Current stable version
- Transactions (deposit, withdraw, get, update notes, search)
- Bulk operations
- Transaction disputes
- Statistics
-
v2 - Future version (in development)
- All v1 features
- Webhooks support
- Advanced filtering
- New authentication schemes
POST /api/v1/transactions/deposit
POST /api/v1/transactions/withdraw
GET /api/v1/transactions/:id
PATCH /api/v1/transactions/:id/notes
GET /api/v1/transactions/search
POST /api/v1/transactions/bulk
GET /api/v1/transactions/bulk/:batchId
POST /api/v1/transactions/:id/dispute
GET /api/v1/transactions/:id/disputes
GET /api/v1/disputes
GET /api/v1/disputes/:id
PATCH /api/v1/disputes/:id
GET /api/v1/stats
GET /api/v1/stats/summary
GET /api/v1/stats/daily
GET /api/transactions -> redirects to /api/v1/transactions
POST /api/transactions -> redirects to /api/v1/transactions
...
Include version in the URL path:
# Using v1
curl -X POST https://api.example.com/api/v1/transactions/deposit \
-H "Content-Type: application/json" \
-d '{"amount": 100, "phone": "+1234567890"}'
# Using v2 (future)
curl -X POST https://api.example.com/api/v2/transactions/deposit \
-H "Content-Type: application/json" \
-d '{"amount": 100, "phone": "+1234567890"}'Specify version in the Accept-Version header:
curl -X POST https://api.example.com/api/transactions/deposit \
-H "Accept-Version: v1" \
-H "Content-Type: application/json" \
-d '{"amount": 100, "phone": "+1234567890"}'The legacy Accept: application/json;version=v1 format is still accepted for
backward compatibility, but Accept-Version is the preferred header.
For backward compatibility, old endpoints still work:
curl -X POST https://api.example.com/api/transactions/deposit \
-H "Content-Type: application/json" \
-d '{"amount": 100, "phone": "+1234567890"}'
# Response includes: API-Version: v1
# Response includes: Deprecation: true
# Response includes: Sunset: <future date>All API responses include version information:
HTTP/1.1 200 OK
API-Version: v1
Vary: Accept, Accept-Version
Deprecation: false
Content-Type: application/json
{
"data": {...}
}
- API-Version: Current API version used for this request
- Vary: Cache control - indicates version headers affect response
- Deprecation: True if endpoint is deprecated
- Sunset: Date when deprecated endpoint will be removed
- Link: Alternative version URL (on Deprecation: true)
Always check the /api/version endpoint for current support status:
curl https://api.example.com/api/version
{
"current": "v1",
"supported": ["v1"],
"deprecated": [],
"upcoming": ["v2"]
}- Request/response structure changes
- New required fields
- Removed deprecated endpoints
- Authentication changes
- Update endpoint URLs from
/api/to/api/v2/ - Update request payloads to match v2 schema
- Update response parsers to handle new v2 format
- Test thoroughly against v2 endpoints
- Migrate in production before v1 sunset date
- v1 Stable: Current
- v2 Beta: Next release
- v1 Deprecation: 180 days after v2 GA
- v1 Sunset: 210 days after v2 GA
HTTP/1.1 400 Bad Request
{
"error": "Unsupported API Version",
"message": "API version v99 is not supported. Supported versions: v1",
"supportedVersions": ["v1"]
}-
URL path (highest priority)
/api/v1/transactions→ usesv1
-
Accept-Version header
Accept-Version: v1→ usesv1
-
Accept header
Accept: application/json;version=v1→ usesv1
-
Default
- No version specified → uses
v1
- No version specified → uses
- Always specify a version explicitly
- Pin to a specific version in production
- Monitor Deprecation headers for upcoming changes
- Plan migrations before sunset dates
- Test against beta versions early
- Never break v1 unless at sunset date
- Prepare v2 early with beta period
- Document breaking changes clearly
- Maintain backward compatibility when possible
- Communicate deprecations in advance
npm test tests/api-versioning.test.ts# Test v1
curl -i https://api.example.com/api/v1/transactions
# Test Accept-Version header
curl -i -H "Accept-Version: v1" \
https://api.example.com/api/transactions
# Test legacy endpoint
curl -i https://api.example.com/api/transactions
# All should work and return:
# API-Version: v1- Requests per version
- Deprecated endpoint usage
- Version mismatch errors
- Migration progress to v2
SELECT
api_version,
COUNT(*) as requests,
DATE(timestamp) as date
FROM api_requests
GROUP BY api_version, DATE(timestamp)
ORDER BY date DESC;- Announce deprecation 180 days before sunset
- Add
Deprecation: trueheader - Add
Sunsetheader with removal date - Add
Linkheader with migration URL
- Keep all endpoints functional
- Provide migration tools/docs
- Adjust rate limits if needed
- Support technical questions
- Remove deprecated endpoints
- Redirect to newer versions (if possible)
- Log migration metrics
- Publish migration summary
Q: Should I use URL versioning or Accept-Version header? A: Use URL path versioning. It's clearer, easier to debug, and better for caching.
Q: How do I know which version to use?
A: Use the latest stable version. Check /api/version for current recommendations.
Q: What happens if I don't specify a version? A: The API defaults to v1, but you should always specify explicitly.
Q: Can I use multiple versions in the same application? A: Yes, but keep them separate. Don't mix v1 and v2 in the same request chain.
Q: When will v1 be deprecated? A: v1 will be supported until at least v2 goes GA + 180 days. We'll announce dates 6 months in advance.
For versioning questions or issues:
- Check this documentation
- Review test cases in
tests/api-versioning.test.ts - File an issue on GitHub
- Contact API support