Recall & Review
beginner
What is the purpose of the
sort parameter in a REST API?The
sort parameter tells the API how to order the results it sends back, like sorting a list of names alphabetically or by date.Click to reveal answer
beginner
How do you specify ascending or descending order using the
sort parameter?You usually add a plus
+ or minus - sign before the field name. For example, sort=+name means ascending by name, and sort=-date means descending by date.Click to reveal answer
intermediate
Can you sort by multiple fields using the
sort parameter? How?Yes! You separate fields with commas. For example,
sort=+category,-price sorts first by category ascending, then by price descending within each category.Click to reveal answer
beginner
Why is sorting important in API responses?
Sorting helps users find information faster and makes data easier to understand, like sorting your contacts by last name to find someone quickly.
Click to reveal answer
beginner
What happens if you don't use a
sort parameter in your API request?The API may return data in a default order, which might be random or based on how data is stored. This can make it harder to find what you want.
Click to reveal answer
What does
sort=-createdAt usually mean in an API request?✗ Incorrect
A minus sign before the field means descending order, so newest items come first.
How do you sort by two fields, first by 'name' ascending, then by 'age' descending?
✗ Incorrect
Use plus for ascending and minus for descending, separated by commas.
If no
sort parameter is given, what is likely true?✗ Incorrect
APIs usually have a default order if no sorting is specified.
Which of these is a valid way to sort descending by price?
✗ Incorrect
A minus sign before the field name indicates descending order.
Why might an API support sorting by multiple fields?
✗ Incorrect
Sorting by multiple fields helps organize data in layers, like sorting books by genre then author.
Explain how the
sort parameter works in a REST API and why it is useful.Think about how you organize lists in daily life.
You got /4 concepts.
Describe how to sort API results by multiple fields and give an example.
Imagine sorting a list of products by category and then price.
You got /4 concepts.