/// <summary> /// Posts an type T object as json to the current API path. /// </summary> /// <param name="apiPath">Enumeration used as string to set the current api path</param> /// <param name="toPost">Identification for the requested database-table</param> public async void Post <T>(PlooderTable apiPath, T toPost) { using (var client = new HttpClient()) { client.BaseAddress = _webServerUri; client.Timeout = TimeSpan.FromSeconds(_timeOut); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PostAsJsonAsync(_webServerUri + apiPath.ToString(), toPost).ConfigureAwait(false); } }
/// <summary> /// Generic function that utilizes reflection to create an adaptive Get method. /// </summary> /// <param name="apiPath">Enumeration used as string to set the current api path.</param> /// <param name="id">Identification for the requested database-table</param> /// <returns></returns> public async Task <T> Get <T>(PlooderTable apiPath, int id) { T data = default(T); using (var client = new HttpClient()) { client.BaseAddress = _webServerUri; client.Timeout = TimeSpan.FromSeconds((_timeOut)); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync(_webServerUri + apiPath.ToString() + "-" + id).ConfigureAwait(false); if (response.IsSuccessStatusCode) { data = await response.Content.ReadAsAsync <T>(); } } return(data); }