public ParkLists GetParks() { string NATIONAL_PARK_API_PATH = BASE_URL + "/parks?limit=30"; string parksData = ""; ParkLists parks = null; httpClient.BaseAddress = new Uri(NATIONAL_PARK_API_PATH); // It can take a few requests to get back a prompt response, if the API has not received // calls in the recent past and the server has put the service on hibernation try { HttpResponseMessage response = httpClient.GetAsync(NATIONAL_PARK_API_PATH).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { parksData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); } if (!parksData.Equals("")) { // JsonConvert is part of the NewtonSoft.Json Nuget package parks = JsonConvert.DeserializeObject <ParkLists>(parksData); } } catch (Exception e) { // This is a useful place to insert a breakpoint and observe the error message Console.WriteLine(e.Message); } return(parks); }
public IActionResult ParkLists() { APIHandler webHandler = new APIHandler(); ParkLists parks = webHandler.GetParks(); return(View(parks)); }