Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a response-body allowed for a HTTP-DELETE-request?

I assume the response code 200 always allows for a response-body, but I can't find any explicit mention of response-bodies for DELETE-requests.

like image 773
scrrr Avatar asked Jul 05 '11 10:07

scrrr


People also ask

Can we send body in HTTP delete request?

If a DELETE request includes an entity body, the body is ignored [...] Additionally here is what RFC2616 (HTTP 1.1) has to say in regard to requests: an entity-body is only present when a message-body is present (section 7.2)

What HTTP response for delete?

A successful response of DELETE requests SHOULD be an HTTP response code 200 (OK) if the response includes an entity describing the status. The status should be 202 (Accepted) if the action has been queued.

Does a delete request return anything?

A DELETE request represents the intent to delete a resource. Thus, if the service successfully handles a DELETE request, what else can it do than returning a 204 (No Content)? After all, the resource has just been removed. A resource is often a member of a collection, or otherwise 'owned' by a container.


2 Answers

It is explicitly mentioned here in the RFC

The short answer is:

You should include a response body with an entity describing the deleted item/resource if you return 200.

202 is something like an asynchronous request/response return status.

204 says explicitly that you do not include a response body

like image 160
fyr Avatar answered Sep 22 '22 09:09

fyr


Yes, you should usually respond with a 200 response code as per the W3C spec:

9.7 DELETE

The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.

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.

If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.

like image 40
Brian Scott Avatar answered Sep 20 '22 09:09

Brian Scott