Skip to content

Instantly share code, notes, and snippets.

@migrap
Created November 9, 2018 20:07
Show Gist options
  • Select an option

  • Save migrap/36d810fbf277ef00c11d3f2f495d1e4c to your computer and use it in GitHub Desktop.

Select an option

Save migrap/36d810fbf277ef00c11d3f2f495d1e4c to your computer and use it in GitHub Desktop.
services.AddHttpClient(name, client => {
    client.BaseAddress = new Uri("https://evo.hostedsuite.com/api");
    client.DefaultRequestHeaders.Add("Accept", "application/json");
});
public async Task<HttpResponseMessage> SendAsync(HttpMethod method, string uri, IReadOnlyDictionary<string, object> parameters = null) {
    var union = (new Dictionary<string, object>() {
        {"CustomerName", _options.Customer },
        {"UserName", _options.Username },
        {"Password", _options.Password }
    }).Union(parameters);

    var content = JsonConvert.SerializeObject(union, Formatting.None, new ParametersJsonConverter());

    var request = new HttpRequestMessage(method, uri) {
        Content = new StringContent(content, Encoding.UTF8, "application/json")
    };

    return await _client.SendAsync(request);
}
svc.AddHostedSuiteClient("doesn't matter for what you're wanting to do", (s, o) => {
  o.Customer = "abcn";
  o.Password = "";
  o.Username = "";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment