How to complete the challenge GET /todos (200) q XML preferred
This challenge uses Accept quality values to say that both JSON and XML are acceptable, but XML is preferred.
Issue a GET request on the
/todosend point with anAcceptheader ofapplication/json;q=0.5, application/xml;q=1to receive results in XML format.
Basic Instructions
- Issue a
GETrequest to/todos - Add the
X-CHALLENGERheader to track challenge completion - Set
Accepttoapplication/json;q=0.5, application/xml;q=1 - Check that the response status is
200 - Check that the response
Content-Typeisapplication/xml
Try it now
GET /todos with q-values preferring XML
Example Request
> GET /todos HTTP/1.1
> Host: apichallenges.com
> X-CHALLENGER: x-challenger-guid
> Accept: application/json;q=0.5, application/xml;q=1
Example Response
< HTTP/1.1 200 OK
< Content-Type: application/xml
< X-Challenger: x-challenger-guid
The response body should contain the todo collection as XML.
Lessons Learned
q=1givesapplication/xmla stronger preference thanapplication/json;q=0.5.- Lower-priority
JSONremains acceptable, so it can still be used if theXMLrepresentation is unavailable. - A negotiated response should be verified with the response
Content-Type, not only with the request header.
Suggested Experiments
- Remove
;q=1fromapplication/xmland confirm that the missing quality value still behaves like1.0. - Change the
XMLquality toq=0.4and watch the preferred response switch toapplication/json. - Add an unsupported high-priority media type before the two supported types and confirm the fallback still works.