I have a WebAPI service and I want it to send an HTTP request to itself. I would like to confirm what the most appropriate way to do this looks like. (Usually, I simply created an instance of another instance of the target controller or refactored the interface code and then made the request this way, but for various reasons I do not want to use this method.)
Is the code below the most appropriate way to make an HTTP request a different controller within the same service?
using (HttpClient client = new HttpClient())
{
var httpRequest = new HttpRequestMessage("GET", "https://localhost/SomeOtherController");
return await client.SendAsync(httpRequest);
}
source
share