How to complete the challenge GET /api/todos (200) ? filter id less than
How to issue a GET request on a top level entity endpoint and filter todos by ids less than a supplied value.
GET /api/todos (200) ? filter id less than
Issue a GET request on the
/api/todosend point with an id filter to return todos with an id less than a supplied value, requesting the response in JSON format.
id<6means return todos where the id is less than 6- most tools and browsers will encode the
<symbol for you when sending the request - the response should contain at least one todo
- the response should be a subset of the current todos, not the full list
- every returned todo should have an
idless than the threshold - the returned todo list should be JSON, so send
Accept: application/jsonif the response is not JSON
Basic Instructions
- Issue a
GETrequest to end point "/api/todos"https://apichallenges.com/api/todos
- The request should have an
X-CHALLENGERheader to track challenge completion - The request should have an
Accept: application/jsonheader so the API returns todos in JSON format - Add an id less-than filter:
https://apichallenges.com/api/todos?id<6
- The response status code should be
200because the request is accepted - Check that every returned todo has an
idless than6
Try it now
If you need to check which todo ids are available, use GET /api/todos. See the solution.
GET /api/todos to see the available todo ids
The sample below uses id<6; edit the threshold if your current data needs a different subset.
GET /api/todos?id<6 to return todos with ids less than 6
Example Request
> GET /api/todos?id<6 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": 2, "title": "lower id todo", "doneStatus": false, "description": "" }
]
}
Lessons Learned
id<filtering checks the lower side of numeric range handling.- The boundary value itself should be excluded from a strict less-than result.
- Empty results can still be valid when no resource satisfies the comparison.
Suggested Experiments
- Use the smallest known todo
idas the boundary and confirm the response becomes empty or very small. - Pair
id<with aGET /api/todosbaseline so you can explain every returnedid.