How to complete the challenge GET /todos (200) ? _sortBy descending

How to issue a GET request on a top level entity endpoint and sort the returned todos in descending order.

GET /todos (200) ? _sortBy descending

Issue a GET request on the /todos end point with a query parameter to sort todos descending by a field.

  • _sortBy is the URL parameter used to sort collection results
  • prefix a field with - to sort descending
  • for example, _sortBy=-id sorts the todos from highest id to lowest id
  • use a field that exists on a todo, such as id, title, doneStatus, or description

Basic Instructions

  • Issue a GET request to end point "/todos"
    • https://apichallenges.com/todos
  • The request should have an X-CHALLENGER header to track challenge completion
  • Add _sortBy=-id as a URL parameter:
    • https://apichallenges.com/todos?_sortBy=-id
  • The response status code should be 200 because the request is accepted
  • Check that the returned todos are ordered by id from highest to lowest

Try it now

GET /todos?_sortBy=-id to sort todos by id descending

Example Request

> GET /todos?_sortBy=-id HTTP/1.1
> Host: apichallenges.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Accept: application/json

Example Response

< HTTP/1.1 200 OK
< Connection: close
< Content-Type: application/json
< X-Challenger: x-challenger-guid

Returned body:

{
  "todos": [
    {
      "id": 10,
      "title": "highest id first",
      "doneStatus": false,
      "description": ""
    },
    {
      "id": 9,
      "title": "then the next id",
      "doneStatus": true,
      "description": ""
    }
  ]
}
Experiment with this endpoint