Example #1
0
        public async Task <T> GetAsync <T>(ApiClientConfig config, string route)
        {
            var request = new HttpRequestMessage(HttpMethod.Get, $"{config.Host}/{route}");

            request.Headers.Authorization = new AuthenticationHeaderValue("ApiKey", config.ApiKey);
            var response = await _http.SendAsync(request);

            var json = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <T>(json));
        }
Example #2
0
        public async Task PostAsync(ApiClientConfig config, string route, object content)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, $"{config.Host}/{route}");
            var json    = JsonConvert.SerializeObject(content);

            request.Content = new StringContent(json);
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            request.Headers.Authorization       = new AuthenticationHeaderValue("ApiKey", config.ApiKey);
            var response = await _http.SendAsync(request);

            if (response.IsSuccessStatusCode == false)
            {
                throw new Exception($"Received {response.StatusCode} response from API.");
            }
        }