2020-03-01 22:46:07 +04:00
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
2025-02-09 17:40:03 +02:00
|
|
|
using System.Text.Json;
|
2020-03-01 22:46:07 +04:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2023-07-29 15:14:52 +03:00
|
|
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class HttpClientExtension
|
2020-03-01 22:46:07 +04:00
|
|
|
{
|
2025-02-09 17:40:03 +02:00
|
|
|
public static async Task<T?> GetJsonAsync<T>(this HttpClient client, Uri requestUri)
|
2020-03-01 22:46:07 +04:00
|
|
|
{
|
2023-07-29 15:14:52 +03:00
|
|
|
var response = await client.GetStringAsync(requestUri);
|
2025-02-09 17:40:03 +02:00
|
|
|
return JsonSerializer.Deserialize<T>(response);
|
2023-07-29 15:14:52 +03:00
|
|
|
}
|
2020-03-01 22:46:07 +04:00
|
|
|
|
2025-02-09 17:40:03 +02:00
|
|
|
public static async Task<T?> GetJsonAsync<T>(this HttpClient client, string requestUri)
|
2023-07-29 15:14:52 +03:00
|
|
|
{
|
|
|
|
|
var response = await client.GetStringAsync(requestUri);
|
2025-02-09 17:40:03 +02:00
|
|
|
return JsonSerializer.Deserialize<T>(response);
|
2020-03-01 22:46:07 +04:00
|
|
|
}
|
|
|
|
|
}
|