Bird
Raised Fist0

Which approach correctly handles this in a single endpoint?

hard🚀 Application Q15 of Q15
Rest API - Versioning Strategies
You want to support versions 1 and 2 of your API using query parameter versioning. Version 1 returns a list of users as strings, and version 2 returns a list of user objects with 'name' and 'id'. Which approach correctly handles this in a single endpoint?
AReturn an error if version parameter is missing or unknown
BChange the URL path to /v1/users and /v2/users instead of query parameters
CIgnore the version parameter and always return the latest format
DUse <code>?version=1</code> to return ['Alice', 'Bob'], and <code>?version=2</code> to return [{'name':'Alice','id':1},{'name':'Bob','id':2}]
Step-by-Step Solution
Solution:
  1. Step 1: Understand query parameter versioning usage

    Clients specify version using ?version=1 or ?version=2 in the same URL.
  2. Step 2: Return different data formats based on version

    Return simple list of strings for version 1, and detailed objects for version 2, matching client request.
  3. Final Answer:

    Use ?version=1 to return ['Alice', 'Bob'], and ?version=2 to return [{'name':'Alice','id':1},{'name':'Bob','id':2}] -> Option D
  4. Quick Check:

    Query param version controls response format [OK]
Quick Trick: Return data format based on version query param [OK]
Common Mistakes:
MISTAKES
  • Changing URL path instead of using query parameters
  • Ignoring version parameter and mixing formats
  • Returning errors unnecessarily for missing versions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes