API versioning is a way to manage changes in an API over time. It helps keep old clients working while allowing new features or fixes in newer versions.
Click to reveal answer
beginner
Name three common API versioning strategies.
1. URI versioning (e.g., /v1/resource) 2. Query parameter versioning (e.g., /resource?version=1) 3. Header versioning (using custom headers like 'Accept-Version')
Click to reveal answer
beginner
How does URI versioning work in an API?
URI versioning adds the version number directly in the URL path, like /api/v1/users. This makes it clear and easy to route requests to the right version.
Click to reveal answer
intermediate
What is a benefit of using header versioning over URI versioning?
Header versioning keeps URLs clean and lets clients specify the version in request headers, which can be more flexible and hides version details from the URL.
Click to reveal answer
intermediate
What is a drawback of query parameter versioning?
Query parameter versioning can be less visible and sometimes caching systems might ignore query parameters, causing unexpected behavior.
Click to reveal answer
Which API versioning strategy places the version number in the URL path?
AQuery parameter versioning
BHeader versioning
CURI versioning
DContent negotiation
✗ Incorrect
URI versioning adds the version directly in the URL path, like /v1/resource.
What header might be used for header-based API versioning?
AAccept-Version
BContent-Type
CAuthorization
DUser-Agent
✗ Incorrect
Custom headers like 'Accept-Version' are used to specify API version in header versioning.
Which versioning strategy can cause issues with caching if not handled properly?
AURI versioning
BQuery parameter versioning
CHeader versioning
DNo versioning
✗ Incorrect
Query parameters might be ignored by some caches, causing stale or wrong responses.
Why is API versioning important?
ATo avoid documentation
BTo break all old clients
CTo make URLs longer
DTo allow changes without breaking existing clients
✗ Incorrect
Versioning lets you improve your API while keeping old clients working.
Which versioning method keeps URLs clean and hides version info from the URL?
B. Using assignment (=) instead of comparison (== or ===) in the if condition
C. Incorrect query parameter name; should be 'ver' not 'version'
D. res.send should be res.json for API responses
Solution
Step 1: Examine the if condition syntax
The condition uses = which assigns '1' to req.query.version instead of comparing.
Step 2: Understand the effect of assignment in condition
Assignment returns '1' (truthy), so the if block always runs, ignoring else.
Final Answer:
Using assignment (=) instead of comparison (== or ===) in the if condition -> Option B
Quick Check:
Use '==' or '===' for comparison, not '=' [OK]
Hint: Use triple equals (===) for comparisons, not single equals (=) [OK]
Common Mistakes:
Confusing assignment with equality check
Assuming missing else block causes bug
Thinking res.send vs res.json causes error here
5. You want to support two API versions in your Node.js app: v1 uses URL path versioning, and v2 uses a custom header X-API-Version. How should you design your Express routes to handle both cleanly?
hard
A. Define separate routes: /api/v1/... for v1, and /api/... with header check for v2
B. Use only URL path versioning for both versions to avoid confusion
C. Use query parameters for v1 and headers for v2 in the same route
D. Combine both version indicators in the URL path like /api/v1/v2/...
Solution
Step 1: Separate versioning methods logically
Use URL path for v1 routes explicitly, e.g., /api/v1/....
Step 2: Use header check for v2 on routes without version in path
Define routes like /api/... and check X-API-Version header to serve v2.
Final Answer:
Define separate routes: /api/v1/... for v1, and /api/... with header check for v2 -> Option A
Quick Check:
Separate routes for path and header versioning [OK]
Hint: Separate routes for path versioning; use header check for others [OK]
Common Mistakes:
Mixing both versions in one URL path
Using query params inconsistently
Ignoring header version check in routes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.