How to complete the challenge GET /api/todos (200) ? filter id single result
How to issue a GET request on a top level entity endpoint and filter by one todo id while there are multiple todos in the database.
GET /api/todos (200) ? filter id single result
Issue a GET request on the
/api/todosend point with an id filter that returns one todo while multiple todos exist in the database, requesting the response in JSON format.
id=3means return the todo where the id is exactly 3- there must be more than one todo in your current session
- the response should contain exactly one todo
- the returned todo should have the same
idthat you filtered on - the returned todo list should be JSON, so send
Accept: application/jsonif the response is not JSON
Basic Instructions
- 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 - Choose an id from the current todo list
- Add the id as an exact filter:
https://apichallenges.com/api/todos?id=3
- The response status code should be
200because the request is accepted - Check that the response contains one todo with the requested id
Try it now
If you need to check which todo ids are available, use GET /api/todos. See the solution.
GET /api/todos to see the available todo ids
If you do not have more than one todo, create another one using POST /api/todos. See the solution.
POST /api/todos to create another todo item
The sample below uses id=3; edit the id if your current data uses a different todo id.
GET /api/todos?id=3 to return one matching todo
Example Request
> GET /api/todos?id=3 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": 3, "title": "single matching todo", "doneStatus": false, "description": "" }
]
}
Lessons Learned
- Filtering by exact
idstill returns a collection wrapper, not a single todo resource. - Exact-match filters are useful for checking query semantics against path lookup semantics.
- A single-result collection should be verified by count and by field values.
Suggested Experiments
- Compare
/api/todos?id=1with/api/todos/1and note the difference between collection and resource responses. - Filter by an
idthat does not exist and confirm the API returns an empty collection rather than404 Not Found.