Skip to main content
blog title image

2 minute read - API Testing API Challenges

Challenge 19 - How To - GET todos invalid Accept - 406

Jul 17, 2021

This post and video shows how to complete the challenge GET /todos (406) to send a GET request for all todos but passing in an ‘accept’ format that the system does not support.

What are the API Challenges?

Our API Challenges Application has a fully functional cloud hosted API, and a set of challenges to work through.

GET /todos (406)

When we issue a request with an accept header, we are asking for a specific content format in the response. But… if we ask for a format that is not supported then the system may reespond with a 406 ‘NOT ACCEPTABLE’ status code.

Issue a GET request on the /todos end point with an Accept header of application/gzip to receive a response with a 406 ‘NOT ACCEPTABLE’ status code.

  • GET request asks for a response with all the todo items
    • e.g. GET /todos to get all the todo items
  • 406 is a success code, in this case it means the accept header is not supported by the system
  • add the X-CHALLENGER header to track progress

Basic Instructions

  • Issue a GET request to end point “/todos”
    • if running locally that endpoint would be
      • http://localhost:4567/todos
    • if running in the cloud that endpoint would be
      • https://apichallenges.herokuapp.com/todos
  • The request should have an Accept header with the value application/gzip
  • The request should have an X-CHALLENGER header to track challenge completion
  • The response status code should be 406 when all the details are valid.
  • Check the body of the message has JSON formatted error message response
  • Check the content-type header in the response has application/json matching the response body

Some systems may simply ignore the ‘accept’ header and return the response in the default format.

Details

> GET /todos HTTP/1.1
> Host: apichallenges.herokuapp.com
> User-Agent: insomnia/2021.2.2
> Accept: application/gzip
> X-CHALLENGER: x-challenger-guid
> 
< HTTP/1.1 406 Not Acceptable
< Connection: close
< Date: Sat, 17 Jul 2021 12:21:37 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:

{
  "errorMessages": [
    "Unrecognised Accept Type"
  ]
}

Overview Video

Patreon ad free version

Learn More and Start Testing