-
Notifications
You must be signed in to change notification settings - Fork 2
/
JokeClient.cs
27 lines (24 loc) · 820 Bytes
/
JokeClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace app
{
public class JokeClient : IJokeClient
{
private readonly string _jokeApi;
public JokeClient(IConfiguration configuration)
{
_jokeApi = configuration["JOKEURL"];
}
public async Task<IEnumerable<Joke>> Jokes()
{
using var httpClient = new HttpClient();
var response = await httpClient.GetAsync(_jokeApi);
var str = await response.Content.ReadAsStringAsync();
var options = new JsonSerializerOptions {PropertyNameCaseInsensitive = true};
return JsonSerializer.Deserialize<IEnumerable<Joke>>(str, options);
}
}
}