I am creating a WebApi and I need to take a key value pairs for my GET
endpoint. I found some examples of using dictionary in POST
method bus this seems not to work with GET
So far I tried this:
[HttpGet]
public IActionResult Get([FromQuery] Dictionary<string, string> myVar)
{
}
I am using swagger to test the API and if I pass {"key":"value"}
I am getting my dictionary with a single pair and value is the entire object I pass in. ({[myVar, {"key":"value"}]}
)
What is the correct way to pass multiple key value pairs to the WebApi for GET
method?
EDIT: The underlying issue was that I was using swagger (swashbuckle) to test my endpoint. And at the moment of this question it doesn't support dynamic query parameters Issue on github. It should support it once OpenApi v3 support is added to swashbucle Issue on github.