Beginner LevelREST APIs & Web Services
What are API Versioning strategies (URI path vs Query parameter vs Custom Header)?
❓ Interview Prompt: Compare URI path versioning (`/v1/`), query parameters (`?v=1`), custom headers (`X-API-Version`), and Accept media type headers.
API Versioning allows introducing breaking changes without breaking existing client integrations:
1
URI Path Versioning (Most Popular): '/api/v1/users' vs '/api/v2/users'.
•
Pros: Highly visible, easily cached by CDNs and proxies.
2
Query Parameter Versioning: '/api/users?version=2'.
3
Custom HTTP Header: 'X-API-Version: 2'.
4
Accept Header (Vendor Media Type / RESTful): 'Accept: application/vnd.company.v2+json'.
Code Implementation Example
typescript
import express from 'express';
const app = express();
// Route level versioning
app.use('/api/v1/users', v1UserRouter);
app.use('/api/v2/users', v2UserRouter);💡Routing versioned API endpoints using Express route handlers.
🎯 Interview Key Takeaway
URI path versioning (/v1/resource) is the most widely adopted pattern due to simplicity and CDN caching support.
#Versioning#API Design#Architecture#Beginner
Back to all REST APIs & Web Services Questions→