
dynamicDictionary<string, object> is only slightly less worseWebClient?await client.GetAsJsonAsync<MyClass>(url);await client.GetAsJsonAsync<MyClass>(url); yeah that for sure simplifies it. Good to know./close dynamicDictionary<string, object>WebClientawait client.GetAsJsonAsync<MyClass>(url);await client.GetAsJsonAsync<MyClass>(url);/closepublic async Task<string> GetRandomJokeAsync()
{
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri($"https://api.humorapi.com/jokes/random?api-key={AppSettings.HumorApiKey}")
};
using var response = await _client.SendAsync(request);
response.EnsureSuccessStatusCode();
var data = JsonSerializer.Deserialize<Dictionary<string, object>>(await response.Content.ReadAsStringAsync()) ?? new Dictionary<string, object>();
return data.TryGetValue("joke", out object value) ? value.ToString() : string.Empty;
}