Can HTTP GET have body?

Guriy Samarin
1 min readMay 28, 2022

--

Of course it can. But you shouldn’t use it. Some major products make use of GET’s body (f.i. Elastic). Still, it goes against RFC 7231 and could break caching and proxying.

Now, let's implement it. Using ASP.NET Core MVC it is straight forward:

using Microsoft.AspNetCore.Mvc;

namespace GetWithBody.Controllers;

[ApiController]
[Route("[controller]")]
public class GetWithBodyController : ControllerBase
{
public record SomeThing(string Some, string Thing);
[HttpGet]
public IActionResult Token([FromBody]SomeThing? data)
{
if (data is null) return BadRequest();

return Ok($"we received {data.Some} and {data.Thing}!");
}
}

And the same goes to DELETE

[HttpDelete]
public IActionResult SomeOtherThing([FromBody] SomeThing? data)
{
if (data is null) return BadRequest();

return Ok($"we aiming to delete {data.Some} and {data.Thing}!");
}

References:

--

--

Guriy Samarin
Guriy Samarin

Written by Guriy Samarin

Software developer at Amazon. Web (mostly backend) development now. My stack — .NET (APS.NET Core MVC).

No responses yet