How to complete the challenge GET /api/todos (200) ? filter description regex

How to issue a GET request on a top level entity endpoint and filter todos by matching the description with a regular expression.

GET /api/todos (200) ? filter description regex

Issue a GET request on the /api/todos end point with a regular expression filter on description that returns todos with non-empty descriptions, requesting the response in JSON format.

  • description~=.*fixture.* means return todos where the description matches the regular expression
  • most tools and browsers will encode any reserved characters for you when sending the request
  • the response should contain at least one todo
  • every returned todo should have a non-empty description
  • every returned description should match the regular expression
  • the returned todo list should be JSON, so send Accept: application/json if the response is not JSON

Basic Instructions

  • Create or update a todo so it has a description containing fixture
  • 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 a regular expression filter:
    • https://apichallenges.com/api/todos?description~=.*fixture.*
  • The response status code should be 200 because the request is accepted
  • Check that every returned description is non-empty and contains fixture

Try it now

If you need a matching todo, create one with a non-empty description containing fixture. See the solution.

POST /api/todos to create a regex filter fixture

Filter by regular expression:

GET /api/todos?description~=.*fixture.* to filter descriptions by regex

Example Request

> GET /api/todos?description~=.*fixture.* 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": 8,
      "title": "regex filter fixture",
      "doneStatus": false,
      "description": "created fixture for regex filter"
    }
  ]
}

Lessons Learned

  • The description~= query uses a regular expression match, which is more expressive than exact filtering.
  • Regex filters need fixture data with predictable text so the assertion is meaningful.
  • Reserved characters in regex query values may be encoded by clients before transmission.

Suggested Experiments

  • Change description~=.*fixture.* to anchor the match, such as ^created, and compare returned todos.
  • Add a todo whose description nearly matches and confirm the regex includes or excludes it as expected.
Experiment with this endpoint