How to complete the challenge POST /api/todos/id (404)

How to use a POST request to try to update a todo item in the application, but the todo item id should not exist.

POST /api/todos/id (404)

Issue a POST request to try and update a todo, but no todo with this id should exist

  • POST request will update a todo if the provided id exists /api/todos/id end point
    • e.g. POST /api/todos/3 for a todo with id==3
  • 404 is a failure code, in this case it means no todo with this id exists
  • The body of the message should be a json or xml partial set of todo details,
  • and the json or xml should be defined in the content-type header
  • The 404 response should have an error message explaining the problem

Basic Instructions

  • Issue a POST request to end point "/api/todos/id"
    • where id is replaced with the id of a todo that does not exist
      • if you don't know any then a GET /api/todos would show a list of todos.
    • https://apichallenges.com/api/todos/id
  • The request should have an X-CHALLENGER header to track challenge completion
  • The content-type in the message should be application/json because we are sending a JSON payload
  • The Payload should have a partial set of todo details. e.g.
{
  "title": "updated title"
}
  • The response status code should be 404 when the details are valid and the id does not exist.
  • The body of the response will be a JSON showing the error.
{
  "errorMessages": [
    "No such todo entity instance with id == 200 found"
  ]
}

Try it now

POST /api/todos/{id} to update a missing todo and trigger 404

Example Request

> POST /api/todos/200 HTTP/1.1
> Host: apichallenges.com
> User-Agent: rest-client
> X-CHALLENGER: x-challenger-guid
> Content-Type: application/json
> Accept: */*
> Content-Length: 32

| 	{
| 		"title": "updated title"
| 	}

Example Response

< HTTP/1.1 404 Not Found
< Connection: close
< Date: Sat, 06 Feb 2021 12:08:58 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

| 	{
| 	  "errorMessages": [
| 	    "No such todo entity instance with id == 200 found"
| 	  ]
| 	}

Lessons Learned

  • POST /api/todos/{id} to a missing id shows that update-style POST still depends on an existing target.
  • 404 Not Found prevents the request from becoming an accidental create.
  • Missing-resource update tests should use a clearly absent id to avoid flaky results.

Suggested Experiments

  • Try the same payload against an existing id and a missing id, then compare 200 OK with 404 Not Found.
  • Create a todo after the failed update and confirm the failed POST did not reserve or create that id.
Experiment with this endpoint