How to complete the challenge GET /todos XML (200)
When we issue a GET request we can use the Accept header to request a specific format of result from the API. In this case we will ask for XML to successfully GET all the todos in XML format.
GET /todos XML (200)
Issue a GET request on the
/todosend point with anAcceptheader ofapplication/xmlto receive results in XML format
GETrequest will receive a response with all the todo items- e.g.
GET /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 XML format- add the
X-CHALLENGERheader to track progress
Basic Instructions
- Issue a
GETrequest to end point "/todos"- if running locally that endpoint would be
https://apichallenges.com/todos
- if running locally that endpoint would be
- The request should have an
Acceptheader specifying XML format by using a value ofapplication/xml - 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 XML format data
- Check the
content-typeheader in the response hasapplication/xml
Try it now
GET /todos with Accept: application/xml to request XML
Example Request
> GET /todos HTTP/1.1
> Host: apichallenges.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Accept: application/xml
Example Response
< HTTP/1.1 200 OK
< Connection: close
< Date: Thu, 22 Apr 2021 16:49:31 GMT
< Content-Type: application/xml
< 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>
<todo>
<doneStatus>false</doneStatus>
<description/>
<id>273</id>
<title>scan paperwork</title>
</todo>
<todo>
<doneStatus>false</doneStatus>
<description/>
<id>277</id>
<title>pay invoices</title>
</todo>
</todos>
Overview Video
Lessons Learned
Accept: application/xmlasks for anXMLrepresentation of the same/todoscollection.- The resource stays the same even though element names, nesting, and parsing rules change from
JSONtoXML. - A successful
XMLresponse should be checked with anXMLparser, not just by spotting angle brackets.
Suggested Experiments
- Compare
Accept: application/xmlwithAccept: application/jsonand confirm the todo count is the same in both representations. - Remove the
Acceptheader after theXMLrequest and note whether the server falls back toapplication/json. - Try
Accept: text/xmland check whether the API treats the older genericXMLmedia type as acceptable. - Try
Accept: application/*+xmlto see whether structured+xmlsuffix negotiation is supported. - Try a vendor-style header such as
Accept: application/vnd.apichallenges.todo+xmland record whether it is treated as todoXMLor rejected. - Try
Accept: application/problem+xmland confirm that an error-document media type is not treated as a normal todo-list representation.