Bird
Raised Fist0
Rest APIprogramming~5 mins

Sort direction (asc, desc) in Rest API - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What does asc mean in sort direction?

asc stands for ascending order. It means sorting from smallest to largest, like A to Z or 1 to 10.

Click to reveal answer
beginner
What does desc mean in sort direction?

desc stands for descending order. It means sorting from largest to smallest, like Z to A or 10 to 1.

Click to reveal answer
beginner
How do you specify sort direction in a REST API query?

You usually add a query parameter like ?sort=fieldname&direction=asc or ?sort=fieldname&direction=desc to tell the server how to sort results.

Click to reveal answer
beginner
Why is specifying sort direction important in APIs?

It helps users get data in the order they want, like newest first or alphabetical order, making data easier to understand and use.

Click to reveal answer
beginner
Example: What does ?sort=price&direction=desc do?

This query sorts items by price from highest to lowest, showing the most expensive items first.

Click to reveal answer
What does asc mean in sort direction?
ASort from largest to smallest
BSort from smallest to largest
CSort randomly
DSort by date only
If you want to see newest items first, which sort direction should you use?
Aasc
Bnone
Crandom
Ddesc
How do you usually tell a REST API to sort results?
ABy sending a sort direction in the query parameters
BBy changing the server code
CBy refreshing the page
DBy using a POST request
What does ?sort=name&direction=desc do?
ASorts names from Z to A
BSorts by date
CSorts names from A to Z
DSorts randomly
Why is sorting data useful in APIs?
ATo slow down the server
BTo hide data
CTo make data easier to find and understand
DTo change data values
Explain the difference between asc and desc sort directions in REST APIs.
Think about sorting numbers or words from smallest to largest or largest to smallest.
You got /3 concepts.
    Describe how you would use query parameters to sort data by price in descending order in a REST API.
    Remember the URL format for sorting.
    You got /3 concepts.

      Practice

      (1/5)
      1.

      What does the direction=asc parameter do in a REST API request?

      easy
      A. Sorts the data in ascending order, from smallest to largest.
      B. Sorts the data in descending order, from largest to smallest.
      C. Filters the data to show only ascending values.
      D. Deletes all data except the first item.

      Solution

      1. Step 1: Understand the meaning of 'asc'

        'asc' stands for ascending, which means sorting from smallest to largest.
      2. Step 2: Apply to REST API sorting

        When used as a direction parameter, it orders the data from smallest to largest values.
      3. Final Answer:

        Sorts the data in ascending order, from smallest to largest. -> Option A
      4. Quick Check:

        direction=asc means ascending order [OK]
      Hint: Asc means smallest to largest order in sorting [OK]
      Common Mistakes:
      • Confusing 'asc' with descending order
      • Thinking 'asc' filters data instead of sorting
      • Assuming 'asc' deletes data
      2.

      Which of the following is the correct way to specify descending sort direction in a REST API URL query?

      https://api.example.com/items?sort=price&_____
      easy
      A. direction=asc
      B. order=asc
      C. sort=desc
      D. direction=desc

      Solution

      1. Step 1: Identify the parameter for sort direction

        The common parameter to specify sort direction is 'direction'.
      2. Step 2: Choose the correct value for descending order

        Descending order is indicated by 'desc'. So the correct query is 'direction=desc'.
      3. Final Answer:

        direction=desc -> Option D
      4. Quick Check:

        Descending sort uses direction=desc [OK]
      Hint: Use direction=desc for descending sort in query [OK]
      Common Mistakes:
      • Using 'sort=desc' instead of 'direction=desc'
      • Mixing 'asc' and 'desc' values
      • Using 'order=asc' which is not standard here
      3.

      Given this REST API response sorted by rating in descending order, what is the first item's rating?

      GET https://api.example.com/movies?sort=rating&direction=desc
      
      Response:
      [
        {"title": "Movie A", "rating": 9.5},
        {"title": "Movie B", "rating": 8.7},
        {"title": "Movie C", "rating": 7.9}
      ]
      medium
      A. 7.9
      B. 8.7
      C. 9.5
      D. Cannot determine

      Solution

      1. Step 1: Understand descending order sorting

        Descending order means highest values come first.
      2. Step 2: Check the first item in the response

        The first item has rating 9.5, which is the highest rating.
      3. Final Answer:

        9.5 -> Option C
      4. Quick Check:

        Descending sort puts 9.5 first [OK]
      Hint: Descending means highest value is first in list [OK]
      Common Mistakes:
      • Picking the last item's rating instead of first
      • Confusing ascending with descending order
      • Choosing 'Cannot determine' without checking response
      4.

      Identify the error in this REST API request URL that tries to sort users by age in descending order:

      https://api.example.com/users?sort=age&direction=descending
      medium
      A. The parameter 'direction' should be 'desc' not 'descending'.
      B. The 'sort' parameter should be 'desc' instead of 'age'.
      C. The URL is missing the 'order' parameter.
      D. The '&' symbol should be replaced with '?' in the URL.

      Solution

      1. Step 1: Check the 'direction' parameter value

        The correct values for direction are 'asc' or 'desc', not 'descending'.
      2. Step 2: Confirm the 'sort' parameter is correct

        'sort=age' is correct to specify sorting by age.
      3. Final Answer:

        The parameter 'direction' should be 'desc' not 'descending'. -> Option A
      4. Quick Check:

        Use 'desc' for descending direction [OK]
      Hint: Use 'desc' not 'descending' for direction [OK]
      Common Mistakes:
      • Using full word 'descending' instead of 'desc'
      • Changing 'sort' parameter incorrectly
      • Misplacing '&' and '?' in URL
      5.

      You want to get a list of products sorted by price ascending, but only those with price greater than 100. Which query parameters correctly combine sorting and filtering?

      hard
      A. sort=price&direction=desc&filter=price>100
      B. filter=price>100&sort=price&direction=asc
      C. sort=price&direction=asc&filter=price=100
      D. direction=asc&filter=price>100

      Solution

      1. Step 1: Identify sorting parameters

        Sorting by price ascending requires 'sort=price' and 'direction=asc'.
      2. Step 2: Add filtering for price greater than 100

        Filtering is done with 'filter=price>100'. The order of parameters does not affect functionality but including all is best practice.
      3. Final Answer:

        filter=price>100&sort=price&direction=asc -> Option B
      4. Quick Check:

        Filter then sort ascending with correct parameters [OK]
      Hint: Combine filter and sort with correct parameters [OK]
      Common Mistakes:
      • Using descending direction instead of ascending
      • Omitting filter parameter
      • Incorrect parameter order causing confusion
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard