Added API versioning to the Ajosave project to support backward compatibility and future API evolution.
- New versioned endpoints: All API routes moved to
/api/v1/ - Backward compatibility: Legacy
/api/routes redirect to/api/v1/with deprecation headers - Middleware-based redirects: Automatic redirection handled in
src/middleware.ts
- GET requests: 301 (Moved Permanently) redirect
- POST/PUT/DELETE/PATCH: 308 (Permanent Redirect) to preserve HTTP method
- Deprecation headers:
X-API-Deprecated: trueX-API-Deprecation-Info: This endpoint is deprecated. Use /api/v1/{endpoint} instead.
- OpenAPI spec: Updated to reflect v1 versioning with new base URLs
- API docs: Now served at
/api/v1/docswith updated title and spec URL - Version info: Added versioning section to API documentation
- Auth routes: NextAuth routes (
/api/auth/) are excluded from automatic redirection to avoid breaking authentication flow
GET /api/v1/circles
POST /api/v1/circles
GET /api/v1/health
GET /api/circles → redirects to /api/v1/circles
POST /api/circles → redirects to /api/v1/circles
GET /api/health → redirects to /api/v1/health
To test the implementation:
-
Check v1 endpoints work:
curl http://localhost:3000/api/v1/health
-
Verify redirects:
curl -I http://localhost:3000/api/health # Should return 301 with Location: /api/v1/health -
Check deprecation headers:
curl -I http://localhost:3000/api/circles # Should include X-API-Deprecated: true
- When introducing breaking changes, create
/api/v2/ - Consider sunset timeline for v1 deprecation
- Monitor usage of legacy endpoints via deprecation headers