0
0
Rest APIprogramming~20 mins

Sort direction (asc, desc) in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sort Direction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this REST API query with ascending sort?

Consider a REST API endpoint that returns a list of users sorted by age. The query parameter sort=age:asc is used.

Given the following user ages in the database: [34, 21, 45, 29], what order of ages will the API return?

A[34, 21, 45, 29]
B[45, 34, 29, 21]
C[21, 29, 34, 45]
D[29, 21, 34, 45]
Attempts:
2 left
💡 Hint

Ascending means from smallest to largest.

Predict Output
intermediate
2:00remaining
What is the output of this REST API query with descending sort?

Using the same user ages [34, 21, 45, 29], what order will the API return if the query parameter is sort=age:desc?

A[45, 34, 29, 21]
B[34, 21, 45, 29]
C[29, 21, 34, 45]
D[21, 29, 34, 45]
Attempts:
2 left
💡 Hint

Descending means from largest to smallest.

🧠 Conceptual
advanced
2:00remaining
Which query parameter correctly sorts by name in ascending order?

You want to get a list of users sorted by their name in ascending order using a REST API. Which query parameter is correct?

Asort=asc:name
Bsort=name:asc
Corder=name:asc
Dsort=ascending:name
Attempts:
2 left
💡 Hint

Look for the format sort=field:direction.

Predict Output
advanced
2:00remaining
What error occurs with an invalid sort direction?

If a REST API receives the query parameter sort=age:upwards, what is the most likely response?

A500 Internal Server Error
B200 OK with unsorted results
C200 OK with results sorted ascending by default
D400 Bad Request with error message about invalid sort direction
Attempts:
2 left
💡 Hint

APIs usually validate query parameters and reject invalid values.

🚀 Application
expert
2:00remaining
How many items are returned when sorting with pagination?

A REST API returns a list of 100 users sorted by age descending. The query parameters are sort=age:desc and limit=10. How many users will be in the response?

A10
B100
C90
DDepends on the API default
Attempts:
2 left
💡 Hint

The limit parameter controls how many items are returned.