I am trying to define a Controller Action in ASP.NET Core 2.2.
The tricky part is that I prefer this to be a GET endpoint, and the data that it must recieve is a collection of custom objects. Here is my sample code:
[Route("api/example")]
[ApiController]
public class ExampleController : ControllerBase
{
[HttpGet("getData")]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
public async Task<IActionResult> GetMarketData([FromQuery] MyObject[] queryData)
{
return this.Ok(0);
}
}
public class MyObject
{
public int A { get; set; }
public int B { get; set; }
}
I am expecting this to bind to something like
http://localhost/api/example/getData/?queryData=[A=1,B=1],queryData=[A=2,B=2]
However I can't seem to get it to work.
(Sending a request to the URL, does not parse the objects, and I receive an empty array in my controller)
I'm not sure if this is the best way to approach this, and maybe I need to change the place where I bind the data from?
The only thing I care about is being able to recieve an array (or some kind of a collection) of MyObject that I can process and return a response. I would also prefer for this to be a GET request, as, after all, I am trying to query this API and get data from it.
I know I can get it to work with using a [FromBody] attribute, but as far as I know GET requests should not use the body.
Any help is gladly appreciated.