Reputation: 451
I have an API that I want to test. This is the signature of one method...
[HttpGet("{param}")]
public async Task<IActionResult> Get(string param, string param2)
{
...
}
In the test project I structure the call this way...
HttpClient client = new HttpClient();
string uri = "http://localhost:63779/api/controller_name/param/";
HttpResponseMessage response = await client.GetAsync(uri);
param is part of the route but how do I get param2 to the method?
Upvotes: 4
Views: 15440
Reputation: 27595
Pass param2
as query string ti the server. The client code:
HttpClient client = new HttpClient();
string uri = "http://localhost:63779/api/controller_name/param/?param2=SOME_VALUE";
HttpResponseMessage response = await client.GetAsync(uri);
Upvotes: 5