I’m starting a REST API to make a Web Application.
Most web sites tell you to delete resources issuing a DELETE HTTP request to an URI like /{resource}/{resource-id}. I’m afraid of deleting some resource that could have been updated since I retrieved it, or even a wrong resource.
Would it be OK to require sending the resource’s timestamp along with the request? I haven’t seen it anywhere, but I think it could be really useful. It would check for concurrency and prevent deleting random resources without even retrieving them before.
Use the HTTP headers of
ETagandIf-Matchwith yourDELETErequest.The client
GETs the resource:The server responds:
The client wants to
DELETEthe resource:Case 1: thing 42 was not changed, it can be deleted. The server responds:
Case 2: thing 42 was changed and does not match the
ETag: "foo-bar-baz". It is not deleted, the server reponds:Variant:
You can also use the headers
Last-ModifiedandIf-Unmodified-Sinceinstead of or in addition toETagandIf-Match.See the Hypertext Transfer Protocol (HTTP) Status Code Registry.