Mario Catillo
Mario Catillo

Reputation: 155

Understanding HTTP DELETE method in a REST API

I wonder about the REST API structure: Is it correct to use the HTTP DELETE method without effectively deleting a resource on the webserver dir but in a database?

Upvotes: 1

Views: 5468

Answers (1)

cassiomolin
cassiomolin

Reputation: 130917

The RFC 7231 defines the semantics of the HTTP DELETE method.

It expresses a deletion operation on the URI mapping (and it doesn't expect that the associated content will be actually deleted from the server). Whether the actual content will be deleted or not or whether it can be restored or not, is up to the server implementation.

See the quote below (highlights are mine):

4.3.5. DELETE

The DELETE method requests that the origin server remove the association between the target resource and its current functionality. In effect, this method is similar to the rm command in UNIX: it expresses a deletion operation on the URI mapping of the origin server rather than an expectation that the previously associated information be deleted.

If the target resource has one or more current representations, they might or might not be destroyed by the origin server, and the associated storage might or might not be reclaimed, depending entirely on the nature of the resource and its implementation by the origin server (which are beyond the scope of this specification). Likewise, other implementation aspects of a resource might need to be deactivated or archived as a result of a DELETE, such as database or gateway connections. In general, it is assumed that the origin server will only allow DELETE on resources for which it has a prescribed mechanism for accomplishing the deletion. [...]

Upvotes: 3

Related Questions