Should deleting a non-existent resource result in a 404 in RESTful Rails? Should deleting a non-existent resource result in a 404 in RESTful Rails? ruby ruby

Should deleting a non-existent resource result in a 404 in RESTful Rails?


UPDATE: It turns out I was wrong: https://stackoverflow.com/a/24713946/14731


Previous answer:HTTP DELETE is an idempotent operation. Invoking it multiple times consecutively must result in the same behavior as the first. Meaning: you shouldn't return HTTP 404.


I don't think you should ever throw the error at the user for the sake of holding up some standard - especially if this is a consumer facing app (as opposed to B2B). But you also shouldn't make your api change its status code just for this one situation. The resource doesn't exist anymore; so a 404 is a proper response.

I think there is a path of least (or lessor - is that even a word???) resistance here. I haven't explored ruby yet so I can't provide any usable implementation; but I'm somewhat experienced with web apps using html/css/js.

If there is some legitimate problem with users clicking a button twice; why not set up the button so that it disables when the request is submitted, and re-enables once the conditions are proper (request has come back)? In other words, avoid the if(this very specific situation) logic by making it impossible to get into the situation you're seeing. I'm assuming ruby has something specifically for handling requests and adding function handlers for different status codes; or at least non-200 status codes.


Rails scaffold code is a suggestion at best. Your instinct to make the error message more user friendly is a good one.