Part 2 - How to retrieve data from the database in the ASP.NET Web API using Http Client

Part 2 - Fetch data from WebApi using Http Client
Name Email City Country
Part 2 - How to retrieve data from the database in the ASP.NET Web API using Http Client
using Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web;
using System.Web.Mvc;

namespace WebApiClient.Web.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Part1()
        {
            return View();
        }

        public ActionResult Part2()
        {
            List<Employee> list = new List<Employee>();
            HttpClient client = new HttpClient();
            var result = client.GetAsync("http://localhost:1963/api/Example").Result;
            if (result.IsSuccessStatusCode)
            {
                list = result.Content.ReadAsAsync<List<Employee>>().Result;
            }
            return View(list);
        }
    }
}

Posted By :