How to complete the challenge QUERY /todos Structured JSON (200)
QUERY is a safe read method that can send query content in the request body. For this challenge, use a Structured JSON query document to request todos where doneStatus=true.
QUERY /todos Structured JSON (200)
Issue a QUERY request on the
/todosend point with a Structured JSON query body to get only todos which are done. There must exist both done and not done todos to pass this challenge.
- Use the
QUERYmethod with/todos. - Add
Content-Type: application/vnd.thingifier.query+json. - Add
Accept: application/jsonso you can inspect the response. - Send a
filterobject for"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/todos
- The request should have an
X-CHALLENGERheader so the challenge is tracked. - The request body should be a Structured JSON query document:
The Structured JSON query body format is described in the HTTP QUERY method reference.
{
"filter": {
"doneStatus": true
}
}
Try it now
If you need fixture data, create one done todo and one not-done todo first. See the solution.
POST /todos to create a done todo fixture
POST /todos to create a not-done comparison todo
Issue the QUERY request with the Structured JSON filter in the body:
QUERY /todos with a Structured JSON doneStatus filter
Example Request
> QUERY /todos HTTP/1.1
> Host: apichallenges.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Content-Type: application/vnd.thingifier.query+json
> Accept: application/json
>
> {"filter":{"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": 43,
"title": "done todo for Structured JSON query",
"doneStatus": true,
"description": "created for query challenge"
}
]
}
Lessons Learned
QUERY /todoscan useContent-Type: application/vnd.thingifier.query+jsonwhen the request body is aStructured JSONquery document.- The body describes query criteria; it is not a todo representation and it does not create or amend data.
- A
filterobject can match fields by exactJSONvalues, so booleans are sent astrueorfalse, not as strings. Structured JSONdiffers fromJSONPath:JSONPathselects from a response-shaped document, whileStructured JSONdescribes query criteria for the API to apply.
Suggested Experiments
- Send
{"filter":{"doneStatus":false}}to return todos that are not done. - Send
{"filter":{"id":{"greaterThan":1,"lessThan":5}}}to filter numeric ids. - Send
{"filter":{"title":{"contains":"query"}}}after creating todos with matching titles. - Send
{"filter":{"doneStatus":false},"sort":[{"field":"title","direction":"asc"}]}to combine filtering and sorting. - Send
{"sort":[{"field":"id","direction":"desc"}],"limit":5,"offset":0}to page through a sorted collection. - Use the method reference for more
QUERYdetails andStructured JSONexamples.