Open staminna opened 6 years ago
@staminna You need to fill the x-www-form-urlencoded POST Body fields to make a successful POST request.
Thanks for quick reply @nomanHasan I can post but not delete. See above error stack
I am also having an issue with delete. I don’t understand how it works: the url has an :id in it in the route file, how do I pass this into the api? Doing /api/todos/[key] returns an error but it deletes the item. If I pass the id in the body of postman req than I get an 404...why? How does the server know the key I pass is the id if I don’t specify it in the req body?
I figured out the error on delete. The delete works but the success code was wrong:
return res.status(204).json({status:204, message: "Succesfully Deleted Item"})
should be:
return res.status(200).json({status:200, message: "Succesfully Deleted Item"})
@williamJmelton Thank your very much for sharing your findings. But according to the HTTP Method definitions a status code of 204 No Content is acceptable as a successful DELETE response. See this -
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
(Section 9.7 DELETE) A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.
The {status, message}
object is not mandatory. The main resource is the Todo object. As we are not returning any Todo object on DELETE, a 204 No Content makes more sense. But 200 OK should be fine too.
@williamJmelton thanks to share your findings but after that change i did face same issue.
I fixed issue on delete. The delete works with success code:
if(deleted.result.n === 0){
should be:
if(deleted.n === 0){
@hjunaidshahid Thanks man! I have no clue why this works but glad I found your comment! Should've been more upvoted!
Hi
The description and date fields are missing in Creating (checked using postman).
Deleting crashes: