For example, we need to have an API method, which get array as input (array of id of devices) and returns list of these devices (full information about each device).
So, there are all attributes of GET method, but it's a bad idea to pass it in url (array can be big), so, it would be better to pass it in body:
[HttpGet("api/deviceNames")]
[ProducesResponseType(typeof(List<DeviceInfo>), StatusCodes.Status200OK)]
public IActionResult GetDeviceNamesByIds([FromBody]List<string> deviceIds)
{
var d = _deviceService.GetDevicesByIds(deviceIds);
return Ok(d);
}
It works and works fine. But many authors don't recommend to use body for GET methods, e.g. https://groups.yahoo.com/neo/groups/rest-discuss/conversations/messages/9962?guccounter=1
Yes. In other words, any HTTP request message is allowed to contain a message body, and thus must parse messages with that in mind. Server semantics for GET, however, are restricted such that a body, if any, has no semantic meaning to the request. The requirements on parsing are separate from the requirements on method semantics.
So, yes, you can send a body with GET, and no, it is never useful to do so.
This is part of the layered design of HTTP/1.1 that will become clear again once the spec is partitioned (work in progress).
....Roy
but, from other side:
Update The RFC2616 referenced as "HTTP/1.1 spec" is now obsolete. In 2014 it was replaced by RFCs 7230-7237. Quote "the message-body SHOULD be ignored when handling the request" has been deleted. It's now just "Request message framing is independent of method semantics, even if the method doesn't define any use for a message body" The 2nd quote "The GET method means retrieve whatever information ... is identified by the Request-URI" was deleted. - From a comment