Bird
0
0

Why does the API call /items?category=electronics&category=books return only electronics items?

medium📝 Debug Q7 of 15
Rest API - Query Parameters and Filtering
Why does the API call /items?category=electronics&category=books return only electronics items?
AThe API merges both categories automatically
BThe API uses the first occurrence of the repeated parameter
CThe API returns an error for repeated parameters
DThe API uses the last occurrence of the repeated parameter
Step-by-Step Solution
Solution:
  1. Step 1: Understand repeated query parameters behavior

    Many APIs take the first or last value when a parameter repeats; here it takes the first.
  2. Step 2: Analyze why only electronics are returned

    Since 'category=electronics' appears first, the API filters by electronics only.
  3. Final Answer:

    The API uses the first occurrence of the repeated parameter -> Option B
  4. Quick Check:

    Repeated params usually use first or last value [OK]
Quick Trick: Avoid repeating query keys; use comma or arrays instead [OK]
Common Mistakes:
MISTAKES
  • Assuming API merges repeated parameters
  • Expecting error on repeated keys
  • Thinking last value is always used

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes