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

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

GET /todos (200) ? _sortBy ascending

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

  • GET request will return items from the /todos end point
  • 200 is the success code meaning the request was accepted
  • _sortBy is the URL parameter used to sort collection results
  • use a todo field name as the value, e.g. _sortBy=title
  • a plain field name sorts ascending
  • +field also means ascending, but using just the field name avoids client URL encoding surprises

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=title as a URL parameter:
    • https://apichallenges.com/todos?_sortBy=title
  • The response status code should be 200 because the request is accepted
  • Check that the returned todos are ordered by title from A to Z

Try it now

GET /todos?_sortBy=title to sort todos by title

Example Request

> GET /todos?_sortBy=title 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": 4,
      "title": "file paperwork",
      "doneStatus": false,
      "description": ""
    },
    {
      "id": 2,
      "title": "process payroll",
      "doneStatus": true,
      "description": ""
    }
  ]
}
Experiment with this endpoint