Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to via GetAsync()

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?

like image 965
John Avatar asked Sep 16 '25 04:09

John


1 Answers

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);
like image 52
amiry jd Avatar answered Sep 17 '25 17:09

amiry jd