public IActionResult Index() { var catBreeds = CatAPIMethods.CatBreeds().Result; //need Result otherwise it's a Task //without it, it just runs the method return(View(catBreeds)); }
//purpose of this controller is so it can talk to API public static async Task <BreedImage> GetBreedImages() { var client = CatAPIMethods.GetHttpClient(); //4 var response = await client.GetAsync("v1/images/search?breed_ids=beng"); //8 take last part of url for here //dont need first slash var catImages = await response.Content.ReadAsAsync <List <BreedImage> >(); //9.catbreed with all the properties //When error when running says it needs to be IList ICollection, make sure you have it as a List return(catImages[0]); }
//home controller, collect, and send info to the view public IActionResult RandomCatByBreed() //10 { var catImages = CatAPIMethods.GetBreedImages().Result; return(View(catImages)); }