How to complete the challenge GET /api/todos (200) ?_limit&_offset

How to issue a GET request on a top level entity endpoint and use pagination to skip records before returning a limited page.

GET /api/todos (200) ?_limit&_offset

Issue a GET request on the /api/todos end point with pagination limit and offset parameters, requesting the response in JSON format.

  • _limit controls the maximum number of todos returned
  • _offset controls how many todos are skipped before returning results
  • if _offset is not supplied, the default offset is 0
  • this challenge is passed by requesting up to 5 todos after skipping 5 todos
  • if your current session has fewer todos after the offset, the response will contain fewer todos
  • header Accept: application/json should be present so the filtered and sorted todo collection is visible as JSON

Basic Instructions

  • Issue a GET request to end point "/api/todos"
    • https://apichallenges.com/api/todos
  • The request should have an X-CHALLENGER header to track challenge completion
  • The request should have an Accept: application/json header so the API returns todos in JSON format
  • Add _limit=5 and _offset=5 as URL parameters:
    • https://apichallenges.com/api/todos?_limit=5&_offset=5
  • The response status code should be 200 because the request is accepted
  • Check that the response body contains no more than 5 todos

Try it now

GET /api/todos?_limit=5&_offset=5 to request the next page of todos

Example Request

> GET /api/todos?_limit=5&_offset=5 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": 6, "title": "archive notes", "doneStatus": false, "description": "" },
    { "id": 7, "title": "send report", "doneStatus": false, "description": "" },
    { "id": 8, "title": "book meeting", "doneStatus": false, "description": "" },
    { "id": 9, "title": "check stock", "doneStatus": false, "description": "" },
    { "id": 10, "title": "close ticket", "doneStatus": false, "description": "" }
  ]
}

Lessons Learned

  • _limit controls page size and _offset controls where the page starts in the collection.
  • Offset-based pagination depends on a stable ordering, even when no explicit sort is supplied.
  • Tests should record ids across pages to catch overlap or skipped records.

Suggested Experiments

  • Request _limit=2&_offset=0, then _limit=2&_offset=2, and check that ids do not repeat.
  • Try an _offset beyond the collection size and observe whether the API returns an empty list or an error.
Experiment with this endpoint