mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-19 00:51:30 -07:00
24 lines
735 B
C#
24 lines
735 B
C#
namespace Bloxstrap.Utility
|
|
{
|
|
internal static class Http
|
|
{
|
|
/// <summary>
|
|
/// Gets and deserializes a JSON API response to the specified object
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="url"></param>
|
|
/// <exception cref="HttpRequestException"></exception>
|
|
/// <exception cref="JsonException"></exception>
|
|
public static async Task<T> GetJson<T>(string url)
|
|
{
|
|
var request = await App.HttpClient.GetAsync(url);
|
|
|
|
request.EnsureSuccessStatusCode();
|
|
|
|
string json = await request.Content.ReadAsStringAsync();
|
|
|
|
return JsonSerializer.Deserialize<T>(json)!;
|
|
}
|
|
}
|
|
}
|