19 lines
588 B
C#
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);
|
|
}
|
|
}
|