Should you respond 404 to a delete for a nonexistent resource?

Hey folks,

Just a quick one. I am using a database (Mongo) that doesn’t error when you try to delete something that doesn’t exist and it’s making me wonder: should a request specifically 404 if a resource doesn’t exist or should it report a success (204)?

Any thoughts? I’m currently leaning towards “yes it should return a 404”

DELETE is idempotent so I think it depends on your circumstances.

What is the client really trying to achieve? Is it:

  1. For the specified resource to be deleted (which might have some interesting side effects that the client specifically wants to invoke), in which case 404 seems appropriate (because the client will have failed to trigger the side effects)
  2. For the specified resource to longer exist in the domain, in which case 204 seems reasonable (because the post-operation state is the same as the client wanted). As an alternative to 204, if you don’t want to force the client to handle a double delete as an error but you do want to notify the client that DELETE has been requested twice, you could respond with 200 + some meta information about the original delete.