I am trying to get my WebAPI POST method to take ANY possible properly formatted Json as input.
For now, what I do is something like this:
[HttpPost("import")]
public IActionResult Import ([FromBody] Request exampleRequest)
{
//...
}
Where the Request class is structured like this:
public class Request
{
public string Json { get; set; }
}
So I have to put something like this into the body of the POST request:
{
"json": "example_Json_in_string_form"
}
So what I do now is I ask for a Json containing a field called "Json" where I put the Json in string form. This method works fine, but I'd prefer a way to directly put the Json in non string form into the POST request.
The reason I didn't create a Model containing the fields of a Json is because I want to be able to take in any properly formatted Json, so that way is off limits (unless I'm missing something).
Is there a way to do what I want to do or am I forced to use the method I'm currently using?