Bird
0
0

Which of the following is the correct syntax to sort API results by date in descending order?

easy📝 Syntax Q3 of 15
Rest API - Query Parameters and Filtering
Which of the following is the correct syntax to sort API results by date in descending order?
A/items?sort=date-
B/items?sort=-date
C/items?sort=desc_date
D/items?sort=date_desc
Step-by-Step Solution
Solution:
  1. Step 1: Recognize the descending sort syntax

    Descending order is indicated by a minus sign before the field name: -date.
  2. Step 2: Eliminate incorrect formats

    Suffixes or prefixes like 'desc_' or 'date-' are not standard for sorting in REST APIs.
  3. Final Answer:

    /items?sort=-date -> Option B
  4. Quick Check:

    Descending sort = sort=-field [OK]
Quick Trick: Minus sign before field means descending [OK]
Common Mistakes:
  • Placing minus sign after field name
  • Using 'desc_' or '_desc' in sort parameter
  • Confusing sort with filter syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes