how to using http client

package required :

  • Newtonsoft.Json

how to intall package Newtonsoft ?

  1. click reight in your project
  2. select manage Nuget Package

Alt text

  1. select browse and search Newtonsoft

Alt text

  1. install this package

#example GET

 public class Something
 {
            public DateTimeOffset Date { get; set; }
            public int TemperatureCelsius { get; set; }
            public string Summary { get; set; }
 }
HttpClientService c = new HttpClientService();
HttpRequestResponseDTO<string> apiCall = await c.ApiCall("http://reqbin.com/echo/get/json", HttpClientService.RequestMethod.GET);
PayloadCreateSomething res = JsonConvert.DeserializeObject<Something>(apiCall.Result);

#example POST

var payload = new PayloadCreateSomething
            {
                Date = DateTime.Parse("2019-08-01"),
                TemperatureCelsius = 25,
                Summary = "Hot"
            };
string jsonString = JsonConvert.SerializeObject(payload);
HttpRequestResponseDTO<string> post = await c.ApiCall("http://reqbin.com/echo/get/json", HttpClientService.RequestMethod.POST, jsonString);