Bird
0
0

You want to document an endpoint that returns a list of products filtered by category and sorted by price. Which structure best captures this in the parameters section?

hard📝 Application Q9 of 15
Rest API - API Documentation
You want to document an endpoint that returns a list of products filtered by category and sorted by price. Which structure best captures this in the parameters section?
A[{"name": "category", "type": "integer", "required": true}]
BNo parameters needed for filtering or sorting
C[{"name": "sort", "type": "boolean", "required": true}]
D[{"name": "category", "type": "string", "required": false}, {"name": "sort", "type": "string", "required": false, "enum": ["price_asc", "price_desc"]}]
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct parameter types and optionality

    Category is a string and optional; sort is a string with limited values and optional.
  2. Step 2: Validate the use of enum for sort options

    Using enum restricts sort values to "price_asc" or "price_desc", clarifying valid inputs.
  3. Final Answer:

    [{"name": "category", "type": "string", "required": false}, {"name": "sort", "type": "string", "required": false, "enum": ["price_asc", "price_desc"]}] -> Option D
  4. Quick Check:

    Parameters with types and enums = correct docs [OK]
Quick Trick: Use enums to restrict parameter values clearly [OK]
Common Mistakes:
MISTAKES
  • Using wrong types for parameters
  • Marking optional parameters as required
  • Ignoring filtering and sorting parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes