Bird
0
0

You want to get a list of books sorted by publication year from newest to oldest using a REST API. Which query string should you use?

hard📝 Application Q8 of 15
Rest API - Query Parameters and Filtering

You want to get a list of books sorted by publication year from newest to oldest using a REST API. Which query string should you use?

A/api/books?sort=publication_year&direction=desc
B/api/books?sort=publication_year&direction=asc
C/api/books?sort=year&direction=desc
D/api/books?sort=publicationYear&direction=ascending
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct field and direction

    The field is 'publication_year' and newest to oldest means descending order.
  2. Step 2: Choose the correct syntax

    /api/books?sort=publication_year&direction=desc uses 'sort=publication_year' and 'direction=desc', which is correct and standard.
  3. Final Answer:

    /api/books?sort=publication_year&direction=desc -> Option A
  4. Quick Check:

    Use 'desc' for newest to oldest sorting [OK]
Quick Trick: Use 'desc' for newest to oldest sorting [OK]
Common Mistakes:
MISTAKES
  • Using asc for newest first
  • Wrong field name
  • Using 'ascending' instead of 'asc'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes