public async Task <RestClientResponse <T> > GetAsync <T>(string url) { using (var httpClient = new HttpClient()) { var response = await httpClient.GetAsync(url); var restClientResponse = new RestClientResponse <T> { StatusCode = (int)response.StatusCode, StatusName = response.StatusCode, Message = response.ReasonPhrase, Response = response.StatusCode != HttpStatusCode.OK ? default(T) : await response.Content.ReadAsAsync <T>() }; return(restClientResponse); } }
public async Task <RestClientResponse <T> > PutAsync <T>(string url, object objectToPut) { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("aplication/json")); var response = await httpClient.PutAsJsonAsync(url, objectToPut); var restClientResponse = new RestClientResponse <T> { StatusCode = (int)response.StatusCode, StatusName = response.StatusCode, Message = response.ReasonPhrase, Response = response.StatusCode != HttpStatusCode.OK ? default(T) : await response.Content.ReadAsAsync <T>() }; return(restClientResponse); } }
public async Task <RestClientResponse <T> > DeleteAsync <T>(string url, string token) { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token); var response = await httpClient.DeleteAsync(url); var restClientResponse = new RestClientResponse <T> { StatusCode = (int)response.StatusCode, StatusName = response.StatusCode, Message = response.ReasonPhrase, Response = response.StatusCode != HttpStatusCode.OK ? default(T) : await response.Content.ReadAsAsync <T>() }; return(restClientResponse); } }