0

I'm trying to get parameters passed in the body (from a form) as DELETE request to the API as

$allVars = $request->getParsedBody();

but for some reason it will be empty when works fine for POST and PUT requests.

Any tips on that?

JackTheKnife
  • 3,795
  • 8
  • 57
  • 117

1 Answers1

1

According to the HTTP specification a DELETE request body should be ignored by servers since there are no "defined semantics":

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

It is a little bit unusual to utilize a request body for DELETE http requests. Many HTTP client libraries don't support it, so it forces a developer to construct requests from low level. Another thing, I guess that some popular web servers if use them as proxy, cut body for DELETE requests as they do for GET by default, so it requires additional configuration for them.

I would put them in the URL path or in the URL query parameters, for example:

DELETE /resource/1234

Is an entity body allowed for an HTTP DELETE request?

Community
  • 1
  • 1
odan
  • 4,757
  • 5
  • 20
  • 49