public async Task <T> PostAsync <T>(string url, object body) where T : new() { _client.BaseUrl = new Uri(url); var request = new RestRequest(); request.AddJsonBody(body); return(await _client.PostAsync <T>(request)); }
public async Task <T> PostAsync <T>(string url, object body, Dictionary <string, string> headers) where T : new() { _client.BaseUrl = new Uri(url); var request = new RestRequest(); headers.ToList().ForEach((KeyValuePair <string, string> header) => { request.AddHeader(header.Key, header.Value); }); request.AddJsonBody(body); return(await _client.PostAsync <T>(request)); }
public async Task <T> GetAsync <T>(string url, Dictionary <string, string> headers) where T : new() { _client.BaseUrl = new Uri(url); var request = new RestRequest(); headers.ToList().ForEach((KeyValuePair <string, string> header) => { request.AddHeader(header.Key, header.Value); }); var response = await Task.FromResult(_client.Get <T>(request)); return(response.Data); }
public async Task <WallhavenSearch> search(string query, string sorting = "toplist", string toprange = "1M", bool random = false) { var rr = new RestRequest("search", Method.GET); if (query != null) { rr.AddQueryParameter("q", query); } if (random) { rr.AddQueryParameter("seed", Guid.NewGuid().ToString("n")); } rr.AddQueryParameter("sorting", sorting); rr.AddQueryParameter("topRange", toprange); return(this.client.Execute(rr)?.Content?.DeserializeObject <WallhavenSearch>()); }
static void Main(string[] args) { var api = GetNorthwindApi(); var categoriesRequest = new RestRequest("categories", RestSharp.Method.GET) { JsonSerializer = new NewtonsoftJsonSerializer(new Newtonsoft.Json.JsonSerializer() { Formatting = Newtonsoft.Json.Formatting.Indented }) }; categoriesRequest.AddQueryParameter("count", "5"); var productsRequest = new RestRequest("products", RestSharp.Method.GET) { JsonSerializer = new NewtonsoftJsonSerializer(new Newtonsoft.Json.JsonSerializer() { Formatting = Newtonsoft.Json.Formatting.Indented }) }; productsRequest.AddQueryParameter("count", "10"); api.ExecuteAsync(categoriesRequest, response => { Console.WriteLine(">>>>>>>>>>>>>>>CATEGORIES<<<<<<<<<<<<<<<"); Console.WriteLine(response.Content); }); api.ExecuteAsync(productsRequest, response => { Console.WriteLine(">>>>>>>>>>>>>>>>PRODUCTS<<<<<<<<<<<<<<<"); Console.WriteLine(response.Content); }); Console.ReadLine(); }