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 /todos end 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 QUERY method with /todos.
  • Add Content-Type: application/vnd.thingifier.query+json.
  • Add Accept: application/json so you can inspect the response.
  • Send a filter object for "doneStatus": true in the request body.
  • Make sure your challenger data has at least one todo with "doneStatus": true and at least one with "doneStatus": false.

Basic Instructions

  • Issue a QUERY request to:
    • https://apichallenges.com/todos
  • The request should have an X-CHALLENGER header 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 /todos can use Content-Type: application/vnd.thingifier.query+json when the request body is a Structured JSON query document.
  • The body describes query criteria; it is not a todo representation and it does not create or amend data.
  • A filter object can match fields by exact JSON values, so booleans are sent as true or false, not as strings.
  • Structured JSON differs from JSONPath: JSONPath selects from a response-shaped document, while Structured JSON describes 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 QUERY details and Structured JSON examples.
Experiment with this endpoint