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?
Ascending means from smallest to largest.
Ascending sort orders the ages from the smallest to the largest value.
Using the same user ages [34, 21, 45, 29], what order will the API return if the query parameter is sort=age:desc?
Descending means from largest to smallest.
Descending sort orders the ages from the largest to the smallest value.
You want to get a list of users sorted by their name in ascending order using a REST API. Which query parameter is correct?
Look for the format sort=field:direction.
The correct format is sort=field:asc to sort ascending by a field.
If a REST API receives the query parameter sort=age:upwards, what is the most likely response?
APIs usually validate query parameters and reject invalid values.
An invalid sort direction causes the API to respond with a 400 error indicating the client sent a bad request.
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?
The limit parameter controls how many items are returned.
The API returns only the number of items specified by limit, here 10.