Is an entity body allowed for an HTTP DELETE request?

后端 未结 15 1579
长发绾君心
长发绾君心 2020-11-21 13:32

When issuing an HTTP DELETE request, the request URI should completely identify the resource to delete. However, is it allowable to add extra meta-data as part of the entity

15条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 13:47

    I don't think a good answer to this has been posted, although there's been lots of great comments on existing answers. I'll lift the gist of those comments into a new answer:

    This paragraph from RFC7231 has been quoted a few times, which does sum it up.

    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.

    What I missed from the other answers was the implication. Yes it is allowed to include a body on DELETE requests, but it's semantically meaningless. What this really means is that issuing a DELETE request with a request body is semantically equivalent to not including a request body.

    Including a request body should not have any effect on the request, so there is never a point in including it.

    tl;dr: Techically a DELETE request with a request body is allowed, but it's never useful to do so.

提交回复
热议问题