public static void Delete(this ISimpleHttpClient client, string url) { var task = Task.Factory.StartNew(() => client.Send <string>(HttpMethod.Delete, url)); task.Wait(); var responseCode = task.Result.Result.Response.StatusCode; if (responseCode != HttpStatusCode.OK) { throw new Exception($"Http return error {responseCode.ToString()}"); } }
public static void Put <T>(this ISimpleHttpClient client, string path, T postBody) { var task = Task.Factory.StartNew(() => client.Send <string>(HttpMethod.Put, path, null, postBody)); task.Wait(); var responseCode = task.Result.Result.Response.StatusCode; if (responseCode != HttpStatusCode.OK) { throw new Exception($"Http return error {responseCode.ToString()}"); } }
public static T Get <T>(this ISimpleHttpClient client, string path) { var task = Task.Factory.StartNew(() => client.Send <string>(HttpMethod.Get, path)); task.Wait(); var responseCode = task.Result.Result.Response.StatusCode; if (responseCode != HttpStatusCode.OK) { throw new Exception($"Http return error {responseCode.ToString()}"); } return(JsonConvert.DeserializeObject <T>(task.Result.Result.Body)); }
public async Task <bool> Connect(string serviceUri) { client = JsonHttpClient.Create(serviceUri + baseApiPath, AddAuthorization); try { var result = await client.Send <string>(HttpMethod.Get, "/"); return(result.Response.StatusCode == HttpStatusCode.OK); } catch { return(false); } }
public async Task <ServiceUserRole> GetUserRole(string token) { return((await client.Send <ServiceUserRole>(HttpMethod.Get, $"/roles")).Body); }