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

In this post, I am going to explain How to retrieve data from the database in the ASP.NET Web API using Http Client.


In the previous part I have explained Part1 - How to retrieve data from the database in the ASP.NET Web API using Jquery

Part 2 - Fetch data from WebApi using Http Client
Name Email City Country
Andrew Fuller [email protected] Tacoma USA
Anne Dodsworth [email protected] London UK
ghth thbgh
Janet Leverling [email protected] Kirkland USA
krishna hari [email protected] in un
Laura Callahan [email protected] Seattle USA
Margaret Peacock [email protected] Redmond USA
Michael Suyama [email protected] London UK
mmm mmm [email protected] mmm mmmm
Nancy Davolio [email protected] Seattle USA
Robert King [email protected] London UK
sdsdg dfgdfg
Sourav Mondal [email protected] Kolkata India
Sourav Mondal [email protected] Kolkata India
Steven Buchanan [email protected] London UK
Part 2 - How to retrieve data from the database in the ASP.NET Web API using Http Client
Share This Tutorial
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 : Sourav Mondal