-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseAPI.cs
More file actions
25 lines (22 loc) · 805 Bytes
/
BaseAPI.cs
File metadata and controls
25 lines (22 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace CoinStatsAPI
{
public abstract class BaseAPI
{
public const string BaseUrl = "https://api.coinstats.app/public/v1";
public static async Task<T> GetDataAsync<T>(string url)
{
var response = await new HttpClient().GetAsync(url);
response.EnsureSuccessStatusCode();
return JsonConvert.DeserializeObject<T>(await response.Content.ReadAsStringAsync(), new JsonSerializerSettings {
NullValueHandling = NullValueHandling.Ignore
});
}
public static async Task<T> GetDataAsync<T>(Request request)
{
return await GetDataAsync<T>(request.FinalUrl);
}
}
}