flower-story/FlowerApp/Extensions.cs
2023-07-27 22:07:24 +08:00

19 lines
588 B
C#

using Blahblah.FlowerApp.Data;
using System.Net.Http.Json;
namespace Blahblah.FlowerApp;
internal sealed class Extensions
{
public static async Task<T?> FetchAsync<T>(string url, CancellationToken cancellation = default)
{
using var client = new HttpClient();
var authorization = Constants.Authorization;
if (authorization != null)
{
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", authorization);
}
return await client.GetFromJsonAsync<T>($"{Constants.BaseUrl}/{url}", cancellation);
}
}