Add project files.
This commit is contained in:
32
MonkeyFinder/Services/MonkeyService.cs
Normal file
32
MonkeyFinder/Services/MonkeyService.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace MonkeyFinder.Services;
|
||||
|
||||
public class MonkeyService
|
||||
{
|
||||
HttpClient httpClient;
|
||||
public MonkeyService()
|
||||
{
|
||||
httpClient = new HttpClient();
|
||||
}
|
||||
|
||||
List<Monkey> monkeyList = new();
|
||||
|
||||
public async Task<List<Monkey>> GetMonkeys()
|
||||
{
|
||||
if (monkeyList?.Count > 0)
|
||||
{
|
||||
return monkeyList;
|
||||
}
|
||||
|
||||
var url = "https://montemagno.com/monkeys.json";
|
||||
var response = await httpClient.GetAsync(url);
|
||||
|
||||
if(response.IsSuccessStatusCode)
|
||||
{
|
||||
monkeyList = await response.Content.ReadFromJsonAsync<List<Monkey>>();
|
||||
}
|
||||
|
||||
return monkeyList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user