todo-api icon indicating copy to clipboard operation
todo-api copied to clipboard

some schema missing in CRUD operations

Open staminna opened this issue 7 years ago • 8 comments

Hi

The description and date fields are missing in Creating (checked using postman).

screen shot 2017-12-16 at 15 11 19

Deleting crashes:

Not Found

404

Error: Not Found
    at /Users/jorge/webapp/angular.io/todo-api/app.js:50:13
    at Layer.handle [as handle_request] (/Users/jorge/webapp/angular.io/todo-api/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/jorge/webapp/angular.io/todo-api/node_modules/express/lib/router/index.js:317:13)
    at /Users/jorge/webapp/angular.io/todo-api/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/jorge/webapp/angular.io/todo-api/node_modules/express/lib/router/index.js:335:12)
    at Immediate.next (/Users/jorge/webapp/angular.io/todo-api/node_modules/express/lib/router/index.js:275:10)
    at Immediate.<anonymous> (/Users/jorge/webapp/angular.io/todo-api/node_modules/express/lib/router/index.js:635:15)
    at runCallback (timers.js:802:20)
    at tryOnImmediate (timers.js:762:5)
    at processImmediate [as _immediateCallback] (timers.js:733:5)

staminna avatar Dec 16 '17 15:12 staminna

@staminna You need to fill the x-www-form-urlencoded POST Body fields to make a successful POST request. todo-api-post-issue

nomanHasan avatar Dec 16 '17 15:12 nomanHasan

Thanks for quick reply @nomanHasan I can post but not delete. See above error stack

staminna avatar Dec 21 '17 10:12 staminna

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?

williamJmelton avatar Feb 15 '18 05:02 williamJmelton

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 avatar Feb 16 '18 02:02 williamJmelton

@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.

nomanHasan avatar Mar 26 '18 09:03 nomanHasan

@williamJmelton thanks to share your findings but after that change i did face same issue.

hjunaidshahid avatar Apr 04 '18 13:04 hjunaidshahid

I fixed issue on delete. The delete works with success code: if(deleted.result.n === 0){ should be: if(deleted.n === 0){

hjunaidshahid avatar Apr 04 '18 13:04 hjunaidshahid

@hjunaidshahid Thanks man! I have no clue why this works but glad I found your comment! Should've been more upvoted!

ackoujens avatar Jul 17 '18 20:07 ackoujens