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 /todos end point with an Accept header of application/json;q=0.5, application/xml;q=1 to receive results in XML format.

Basic Instructions

  • Issue a GET request to /todos
  • Add the X-CHALLENGER header to track challenge completion
  • Set Accept to application/json;q=0.5, application/xml;q=1
  • Check that the response status is 200
  • Check that the response Content-Type is application/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=1 gives application/xml a stronger preference than application/json;q=0.5.
  • Lower-priority JSON remains acceptable, so it can still be used if the XML representation is unavailable.
  • A negotiated response should be verified with the response Content-Type, not only with the request header.

Suggested Experiments

  • Remove ;q=1 from application/xml and confirm that the missing quality value still behaves like 1.0.
  • Change the XML quality to q=0.4 and watch the preferred response switch to application/json.
  • Add an unsupported high-priority media type before the two supported types and confirm the fallback still works.
Experiment with this endpoint