HTTP delete method has a body?

Question:

In the MDN documentation :

Request has a body No

The successful answer has a body No

Safe No

idempotent yes

cacheable no

Accepted in HTML forms No

I also saw answers here on the site saying that, like GET, DELETE has no body

But I did a test with Node.js + Express and Postman. I was able to send a DELETE request with a body and show it on the console

So, after all, does the HTTP delete method have a body?

Answer:

Owning, everyone owns'. The body is an attribute of an abstraction superior to the request entity; that is, every HTTP request is, like every HTTP response, an HTTP message and every message can be composed of start line , headers and body.

 HTTP-message   = start-line
                  *( header-field CRLF )
                  CRLF
                  [ message-body ]

In fact, the only thing that differentiates a request from a response is just the start line .

Even in RFC 7231, which is the most current specification, when it defines the GET method , it does not mention that it has no body; on the contrary, it has the following quote:

A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.

Which, in loose translation, would be that the payload (body) of a GET request has no defined semantics; a GET request with body content may eventually be rejected in some implementations. So, if your application needs a body in a GET request, there's nothing wrong.

A simple case to visualize is to imagine that you have a route that brings the products sold in a virtual store:

/produtos

And you want to implement filters so that you can select which products will be returned.

/produtos?data_cadastro.de=2018-05-01&data_cadastro.ate=2018-05-05
/produtos?preco.ate=100
/produtos?condicao=novo,usado
/produtos?possui_garantia=1
/produtos?nome.contem=camiseta
/produtos?frete_gratis=1

And another hundred other possible filters. Imagine the size of the URL to load so much information? For simplicity, you might as well pass all the information through the requisition body.

The same happens with the DELETE method, although much less frequently, since you would hardly have such complexity in deleting a resource, but if necessary, there is no problem at all.


(1): All methods have a body, including HEAD, however, by definition, any content present in its body should be ignored by the server when generating the HTTP response.

Scroll to Top