How to complete the challenge QUERY /api/todos (200)
QUERY is a safe read method that lets you send query content in the request body. For this challenge, use it to request todos where doneStatus=true.
QUERY /api/todos (200)
Issue a QUERY request on the
/api/todosend point with form-encoded query content to get only todos which are done. There must exist both done and not done todos to pass this challenge.
- Use the
QUERYmethod with/api/todos. - Add
Content-Type: application/x-www-form-urlencoded. - Add
Accept: application/jsonif you want a JSON response. - Send
doneStatus=truein the request body. - Make sure your challenger data has at least one todo with
"doneStatus": trueand at least one with"doneStatus": false.
Basic Instructions
- Issue a
QUERYrequest to:https://apichallenges.com/api/todos
- The request should have an
X-CHALLENGERheader so the challenge is tracked. - The request body should be form URL encoded:
doneStatus=true
Try it now
If you need fixture data, create one done todo and one not-done todo first. See the solution.
POST /api/todos to create a done todo fixture
POST /api/todos to create a not-done comparison todo
Issue the QUERY request with the filter in the body:
QUERY /api/todos with doneStatus=true to return only done todos
Example Request
> QUERY /api/todos HTTP/1.1
> Host: apichallenges.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Content-Type: application/x-www-form-urlencoded
> Accept: application/json
>
> doneStatus=true
Example Response
< HTTP/1.1 200 OK
< Content-Type: application/json
< Accept-Query: application/x-www-form-urlencoded, application/jsonpath, application/vnd.thingifier.query+json
< X-Challenger: x-challenger-guid
Returned body:
{
"todos": [
{
"id": 41,
"title": "done todo for query",
"doneStatus": true,
"description": "created for query challenge"
}
]
}
Lessons Learned
QUERY /api/todosis a safe read that sends filter criteria in the request body.Content-Type: application/x-www-form-urlencodeddescribes the query body, whileAcceptdescribes the returned representation.Accept-Queryin the response documents which query content types are supported.
Suggested Experiments
- Send
doneStatus=falsein theQUERYbody and compare with thedoneStatus=trueresult. - Repeat the same criteria as
GET /api/todos?doneStatus=trueand compare URL visibility with body-based criteria. - Try the same completed-todo filter as a
JSONPathQUERYbody withContent-Type: application/jsonpathand$.todos[?(@.doneStatus == true)]. - Try the same completed-todo filter as a
Structured JSONQUERYbody withContent-Type: application/vnd.thingifier.query+jsonand{"filter":{"doneStatus":true}}. - Read the method reference for more
QUERYbody formats, includingapplication/jsonpathandapplication/vnd.thingifier.query+json.