public class IntegrationService
private string _apiBaseUrl;
public IntegrationService(string apiBaseUrl, WebProxy proxy = null)
_apiBaseUrl = apiBaseUrl;
/// Creates a new HttpClient instance that can be used to make HTTP requests to the API endpoint with the endpoint and proxy precofigured
/// Supports basic HTTP methods and configurations. Essentially enables client to call a function on another application's route with
/// params as a single POST DTO if necessary
public HttpClient GetClient()
var handler = new HttpClientHandler()
client = new HttpClient(handler);
client = new HttpClient();
client.BaseAddress = new Uri(_apiBaseUrl);
public async Task<string> Get(string path)
using (var client = GetClient())
var response = await client.GetStringAsync(path);
public async Task<T> Get<T>(string path)
using (var client = GetClient())
var response = await client.GetStringAsync(path);
var data = JsonConvert.DeserializeObject<T>(response);
public async Task<string> Post(string path, object requestData)
using (var client = GetClient())
var requestContent = new StringContent(
JsonConvert.SerializeObject(requestData),
var response = await client.PostAsync(path, requestContent);
var responseString = await response.Content.ReadAsStringAsync();
public async Task<T> Post<T>(string path, object requestData)
using (var client = GetClient())
var requestContent = new StringContent(
JsonConvert.SerializeObject(requestData),
var response = await client.PostAsync(path, requestContent);
var responseString = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<T>(responseString);
public async Task<string> Put(string path, object requestData)
using (var client = GetClient())
var requestContent = new StringContent(
JsonConvert.SerializeObject(requestData),
var response = await client.PutAsync(path, requestContent);
var responseString = await response.Content.ReadAsStringAsync();
public async Task<T> Put<T>(string path, object requestData)
using (var client = GetClient())
var requestContent = new StringContent(
JsonConvert.SerializeObject(requestData),
var response = await client.PutAsync(path, requestContent);
var responseString = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<T>(responseString);
public async Task<string> Delete(string path)
using (var client = GetClient())
var response = await client.DeleteAsync(path);
var responseString = await response.Content.ReadAsStringAsync();
public async Task<T> Delete<T>(string path)
using (var client = GetClient())
var response = await client.DeleteAsync(path);
var responseString = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<T>(responseString);
/// Proxy settings, needed for accessing accross tiers
public class ProxySettings
public string Endpoint { get; set; }
public bool BypassOnLocal { get; set; } = true;
public bool EnvironmentHasProxy() => !string.IsNullOrEmpty(Endpoint);