Performance: API versioning strategies
MEDIUM IMPACT
API versioning strategies affect the server response time and client load speed by influencing routing complexity and cache efficiency.
app.use('/api/v1', v1Router); app.use('/api/v2', v2Router);
app.use('/api', (req, res, next) => { if (req.headers['api-version'] === '1') { // handle version 1 } else if (req.headers['api-version'] === '2') { // handle version 2 } else { res.status(400).send('Unsupported API version'); } });
| Pattern | Routing Complexity | Conditional Checks | Cache Efficiency | Verdict |
|---|---|---|---|---|
| Header-based versioning with conditional logic | High | Multiple per request | Low | [X] Bad |
| URL path versioning with separate routes | Low | Single per request | High | [OK] Good |