Good Day All
I am using ASP.NET Core 3.1. I need to bind controller parameters to body (they are too large to fit in the URL). I do not wish to create a DTO just for a single method (I also have multiple endpoints, which will end up requiring a lot of throwaway DTOs). This isn't possible out of the box, and all current online help seems to be focused to the old .NET Framework Web Api.
In simple terms, given the following controller:
public class GreetController : ControllerBase
{
public string Index(string firstname, string lastname)
=> $"Hello {firstname} {lastname}";
}
The following curl command:
curl -X GET --header "Content-Type: application/json" --data \
"{\"firstname\":\"John\",\"lastname\":\"Doe\"}" https://[Url]/Greet/
should return Hello John Doe, but instead the parameters are null. Adding [FromBody] also does not work. I need this to work for Json and Xml request bodies. I am aware that this can be done with URI parameters. However, I have some parameters which are too large for a URI therefore they must be in the request body.
NB 2: Please do not include a long-winded explanation about why this doesn't comply with REST.
