Example #1
0
        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()}");
            }
        }
Example #2
0
        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()}");
            }
        }
Example #3
0
        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));
        }
Example #4
0
        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);
            }
        }
Example #5
0
 public async Task <ServiceUserRole> GetUserRole(string token)
 {
     return((await client.Send <ServiceUserRole>(HttpMethod.Get, $"/roles")).Body);
 }