I'm trying to create a rudimentary API gateway, that forwards requests to api services. In this example, there are 4 query string params, that would need to be included in the pass. Is there any way to avoid rebuilding the query string, and simply rerouting the request to the service?
public class WipController : Controller
{
public readonly string BaseServiceUrl = "http://localhost:48535";
[AllowAnonymous]
[HttpGet("api/wip/timekeeper/{timekeeper}/clients")]
public async Task<JsonResult> Get(string timekeeper, string endDate, string sortBy, string sortDirection)
{
using (var client = new HttpClient())
{
var url = new Uri(string.Format("{0}/api/wip/timekeeper/" + timekeeper + "/clients", BaseServiceUrl));
var response = await client.GetAsync(url);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new Exception("There was an error retrieving the set of clients for the timekeeper.");
}
var result = await response.Content.ReadAsStringAsync();
return Json(new { result });
}
}
}