How to complete the challenge GET /api/todos (200) ? filter description wildcard
How to issue a GET request on a top level entity endpoint and filter todos by matching the description with a wildcard pattern.
GET /api/todos (200) ? filter description wildcard
Issue a GET request on the
/api/todosend point with a wildcard filter on description that returns todos with non-empty descriptions, requesting the response in JSON format.
description*=*fixture*means return todos where the description containsfixture*matches any number of characters?matches a single character- most tools and browsers will encode reserved characters for you when sending the request
- every returned todo should have a non-empty matching
description - the returned todo list should be JSON, so send
Accept: application/jsonif the response is not JSON
Basic Instructions
- Create or update a todo so it has a description containing
fixture - 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 a wildcard filter:
https://apichallenges.com/api/todos?description*=*fixture*
- The response status code should be
200because 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 wildcard filter fixture
Filter by wildcard:
GET /api/todos?description*=*fixture* to filter descriptions by wildcard
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": 9,
"title": "wildcard filter fixture",
"doneStatus": false,
"description": "created fixture for wildcard filter"
}
]
}
Lessons Learned
- The
description*=query uses wildcard matching rather than regular-expression syntax. *and?patterns are easier for broad searches but less precise than regex filters.- Wildcard tests should prove both matching and non-matching descriptions.
Suggested Experiments
- Change the wildcard from
*fixture*tocreated*and compare how many descriptions match. - Try a single-character
?wildcard in the pattern and confirm it behaves differently from*.