feat(backend): Add API Versioning with Header-Based Version Negotiation - #312
Merged
Conversation
|
@jotel-dev is attempting to deploy a commit to the Jaja's projects Team on Vercel. A member of the Team first needs to authorize it. |
…s - Add API_DEFAULT_VERSION configuration (default: 1.0) - Update versioning middleware to use default version instead of latest - Update app.ts to default to v1 when no version is negotiated - Update tests to reflect new default behavior - This ensures existing tests continue to pass while allowing v2 opt-in
Contributor
Author
|
All the CI checks (backend, frontend, e2e-fullstack, smart-contracts) are passing and there's no conflict. The Vercel check is failing with "Authorization required to deploy" though — that looks like it needs a maintainer to approve/authorize the deployment on Vercel's side rather than a code fix on my end. Could someone with access take a look? |
devJaja
self-requested a review
August 25, 2026 15:11
devJaja
approved these changes
Aug 25, 2026
devJaja
left a comment
Contributor
There was a problem hiding this comment.
Solid Implementation @jotel-dev
LGTM
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #268
Summary
This PR implements header-based API versioning to enable backward-compatible API evolution without breaking existing clients. The implementation allows clients to specify their desired API version via the API-Version header, while maintaining support for legacy versions and providing enhanced response formats for newer versions.
The versioning system includes:
Changes
New Files Created
backend/src/api/middleware/versioning.ts
backend/src/api/middleware/versioning.test.ts
backend/src/api/routes/v1/tasks.ts
backend/src/api/routes/v2/tasks.ts
Modified Files
backend/src/api/app.ts
backend/src/config/index.ts
backend/src/api/types/express.d.ts
backend/src/api/routes/tasks.ts
Technical Implementation Details
Version Negotiation Flow
Request Processing:
Version Resolution:
Response Headers:
Version-Specific Routing
The routing logic uses simple version prefix matching:
Response Format Differences
v1 Response Format:
{
"taskId": "task_abc123",
"dagPreview": {...},
"status": "queued"
}
v2 Response Format:
{
"data": {
"taskId": "task_abc123",
"dagPreview": {...},
"status": "queued"
},
"_meta": {
"version": "2.0",
"timestamp": "2026-08-25T06:00:00.000Z",
"requestId": "uuid-here",
"apiVersion": "2.0"
},
"_links": {
"self": "/api/tasks/task_abc123",
"stream": "/api/tasks/task_abc123/stream"
}
}
Testing
Unit Tests
✅ Version negotiation with valid client-specified versions
✅ Default version fallback when header is omitted
✅ Rejection of unsupported versions with proper error messages
✅ Rejection of invalid version formats
✅ Deprecation header functionality for v1.x versions
✅ Sunset header functionality when configured
✅ Version parsing and comparison utilities
✅ Configuration fallback when config not loaded
Integration Testing
✅ TypeScript compilation successful
✅ Build process completes without errors
✅ Middleware chain integration with existing routes
✅ Version-specific routing logic verification
Manual Testing Scenarios
Configuration
Environment Variables
API Versioning Configuration
API_LATEST_VERSION=2.0 # Latest supported version
API_SUPPORTED_VERSIONS=1.0,1.1,2.0 # Comma-separated supported versions
API_V1_SUNSET_DATE=2024-12-31 # Optional sunset date for v1
Default Behavior
Migration Guide
For API Consumers
Existing Clients (No Changes Required):
Clients Requiring v1 Format:
Add API-Version header to requests
curl -H "API-Version: 1.0" https://api.example.com/api/tasks
Clients Wanting Latest Features:
Explicitly request latest version
curl -H "API-Version: 2.0" https://api.example.com/api/tasks
For Developers
Adding New API Versions:
Deprecating Old Versions:
Related Issue
Resolves #268 - API Versioning with Header-Based Version Negotiation
Breaking Changes
None. This implementation is fully backward compatible:
Future Enhancements
Potential improvements for future PRs:
Checklist