Skip to main content

Jul 17, 2021 - 2 minute read - API Testing API Challenges Evil Tester

Challenge 22 - How To - POST todos (415) unsupported

This post and video shows how to complete the challenge POST /todos (415) to send a POST request to try and create a todo item but with unsupported content type.

What are the API Challenges?

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

POST /todos (415)

Issue a POST request on the /todos end point with an unsupported content type to generate a 415 status code

For this challenge we issue a request with a content-type which is unsupported.

  • POST request means we will send information in the body of the message
    • e.g. POST /todos sends to the todos endpoint
  • unsupported content type means that we will set content-type to something unknown eg. bob
  • add the X-CHALLENGER header to track progress
  • we know it has been rejected when we receive a 415 response
  • the body of the response should contain the full details of the error message

Basic Instructions

  • Issue a POST 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 Content-Type header with an unsupported value e.g bob
  • add a valid payload, but it won’t match the content type so doesn’t matter, but adding a valid payload makes sure that the system is not ignoring the content type specified.
  • The request should have an X-CHALLENGER header to track challenge completion
  • The response status code should be 415 when all the details are valid.
  • Check the body of the response has JSON formatted error response
    • the system defaults to json for errors

Extras:

  • try setting the ‘accept’ header to specify the format of the error message in the response

Details

> POST /todos HTTP/1.1
> Host: apichallenges.herokuapp.com
> User-Agent: insomnia/2021.2.2
> X-CHALLENGER: x-challenger-guid
> Content-Type: bob
> Accept: */*
> Content-Length: 106

|    {
|       "title": "create todo process payroll",
|       "doneStatus": true,
|       "description": ""
|     }

< HTTP/1.1 415 Unsupported Media Type
< Connection: close
< Date: Sat, 17 Jul 2021 13:57:54 GMT
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: *
< X-Challenger: 19b81e3e-841f-41a9-91c1-373f69091a56
< Server: Jetty(9.4.z-SNAPSHOT)
< Via: 1.1 vegur

Example Response body:

{
  "errorMessages": [
    "Unsupported Content Type - bob"
  ]
}

Overview Video

Watch on YouTube

Patreon ad free version

Learn More and Start Testing


You will need a Github account to comment. Or you can contact me with your comment.

I reserve the right to delete spam comments e.g. if your comment adds no value and its purpose is simply to create a backlink to another site offering training, or courses, etc.