2020-03-01 22:46:07 +04:00
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
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
|
|
|
{
|
2023-07-29 15:14:52 +03: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);
|
|
|
|
|
return JsonConvert.DeserializeObject<T>(response);
|
|
|
|
|
}
|
2020-03-01 22:46:07 +04:00
|
|
|
|
2023-07-29 15:14:52 +03:00
|
|
|
public static async Task<T> GetJsonAsync<T>(this HttpClient client, string requestUri)
|
|
|
|
|
{
|
|
|
|
|
var response = await client.GetStringAsync(requestUri);
|
|
|
|
|
return JsonConvert.DeserializeObject<T>(response);
|
2020-03-01 22:46:07 +04:00
|
|
|
}
|
|
|
|
|
}
|