2

According to the RFC7231 standard:

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.

In my example I am using ASP.NET Core WebApi and I would like to use a request body for an HTTP delete method. Fortunately it works, but I can't find any documentation that confirms that a request body is allowed / supported in ASP.NET Core WebApi.

[HttpDelete("{id}")]
public async Task<ActionResult<bool>> Delete(int id, [FromBody] AnyRequestBodyType body)
{
    // Do some checks with the param "body" here.
    // If everything is OK, the resource will be deleted. 
    // Otherwise, I want to return an HTTP 4xx error. 
}

Can I be sure that the API will work in future ASP.NET Core WebAPI releases?

Do you have any other suggestions? I don't want to pass the parameter via query string because the AnyRequestBodyType is "complex" and a url-encoded request would no longer be readable or "manually executeable".

mi_hoe
  • 21
  • 2
  • You're more likely to have problems sending DELETE requests with a body, many libraries and utilities ignore the body when sending such requests. In my experience, I don't believe ASP.Net cares whether you have a body or not for any request type. The `HTTPDelete` attribute is part of routing and model binding seems to work as with other request methods. – phuzi Jul 02 '21 at 08:40
  • I understand the challenge. If the resource does not have a specific id maybe you can create a specific controller (xDeleteController) with a post method. In the case of a multi-resource or multi-item delete. I've sort of wrestled with using delete. I'm trying to stay true to the standard. Fortunately I'm using a database w/individual primary keys (never compound, I use unique indices for that) and the record can point to different resources (like a png file+) to make it work. Therefore a single id can delete a bunch of resources if needed. – lcj Jun 14 '22 at 13:04

0 Answers0