GET all the todos in JSON format
How to complete the challenge GET /api/todos JSON (200) to successfully GET all the todos in JSON format.
GET /api/todos JSON (200)
Issue a GET request on the
/api/todosend point with anAcceptheader ofapplication/jsonto receive results in JSON format
GETrequest will receive a response with all the todo items- e.g.
GET /api/todosto get all the todo items
- e.g.
200is a success code, in this case it means the end point exists and the todo items were returnedAcceptmeans that anAcceptheader was added to specify that the todos should be returned in JSON format- add the
X-CHALLENGERheader to track progress
Basic Instructions
- Issue a
GETrequest to end point "/api/todos"- if running locally that endpoint would be
https://apichallenges.com/api/todos
- if running locally that endpoint would be
- The request should have an
Acceptheader specifying JSON format by using a value ofapplication/json - The request should have an
X-CHALLENGERheader to track challenge completion - The response status code should be
200when all the details are valid. - Check the body of the message has JSON format data
- Check the
content-typeheader in the response hasapplication/json
Try it now
GET /api/todos with Accept: application/json to request JSON
Example Request
> GET /api/todos 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
< Date: Sun, 09 May 2021 11:07:48 GMT
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: *
< X-Challenger: x-challenger-guid
< Server: Jetty(9.4.z-SNAPSHOT)
< Via: 1.1 vegur
Example Response body:
{
"todos": [
{
"id": 16,
"title": "process payroll",
"doneStatus": false,
"description": ""
},
{
"id": 15,
"title": "pay invoices",
"doneStatus": false,
"description": ""
}
]
}
Overview Video
Lessons Learned
Accept: application/jsonis an explicit request forJSON, not just acceptance of the server default.Content-Typeshould confirm the negotiated response, but the body should still be parsed asJSON.+jsonmedia types describeJSON-shaped bodies; they still need explicit server support.
Suggested Experiments
- Compare
Accept: application/jsonwithAccept: */*;*/*means any response format is acceptable, so check whether the server choosesJSONas the default. - Try
Accept: application/*+jsonto ask for any structured+jsonmedia type, then compare the status code andContent-Typewith the standardapplication/jsonresponse. - Try a specific
+jsonmedia type such asapplication/problem+jsonorapplication/vnd.api+json; these still describeJSONbodies, but the API may reject them if it does not support that representation. - Send
Accept: application/json, application/xml;q=0.5and confirm thatJSONis preferred overXMLwhen both formats are acceptable.