| Method Name | Method Description |
| GetAsync | Sends a GET request to the specified Uri as an asynchronous operation. |
| GetByteArrayAsync | Sends a GET request to the specified Uri and returns the response body as a byte array in an asynchronous operation. |
| GetStreamAsync | Sends a GET request to the specified Uri and returns the response body as a stream in an asynchronous operation. |
| GetStringAsync | Sends a GET request to the specified Uri and returns the response body as a string in an asynchronous operation. |
| PostAsync | Sends a POST request to the specified Uri as an asynchronous operation. |
| PostAsJsonAsync | Sends a POST request as an asynchronous operation to the specified Uri with the given value serialized as JSON. |
| PostAsXmlAsync | Sends a POST request as an asynchronous operation to the specified Uri with the given value serialized as XML. |
| PutAsync | Sends a PUT request to the specified Uri as an asynchronous operation. |
| PutAsJsonAsync | Sends a PUT request as an asynchronous operation to the specified Uri with the given value serialized as JSON. |
| PutAsXmlAsync | Sends a PUT request as an asynchronous operation to the specified Uri with the given value serialized as XML. |
| DeleteAsync | Sends a DELETE request to the specified Uri as an asynchronous operation. |
- ASP.NET Web API Using MVC And Entity Framework - Part One
- ASP.NET Web API Using MVC, Entity Framework And jQuery For Retrieve Data - Part Two
- Reuse The Model Classes Of Entity Data Model(.edmx) To Multiple Projects Using Class Library In ASP.NET Web API - Part Three
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Web;
- using System.Web.Mvc;
- using Entities;
- namespace SatyaConsumingApi.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:47250/api/satya").Result;
- if (result.IsSuccessStatusCode)
- {
- list = result.Content.ReadAsAsync<List<Employee>>().Result;
- }
- return View(list);
- }
- }
- }
- HttpClient client = new HttpClient();
- using System.Net.Http;
- using Entities;
- using Entities;
- var result = client.GetAsync("http://localhost:47250/api/satya").Result;
- var result = client.GetAsync("http://localhost:47250/api/satya").Result;
- if (result.IsSuccessStatusCode)
- {
- }
- if (result.IsSuccessStatusCode)
- {
- list = result.Content.ReadAsAsync<List<Employee>>().Result;
- }
- PM> install-package Microsoft.AspNet.WebApi.Client
Just right click on your project, go to Manage NuGet Packages search for Microsoft.AspNet.WebApi.Client install it and you will have access to the extension method.
- return View(list);
- @model IEnumerable<Entities.Employee>
- @{
- ViewBag.Title = "Satyaprakash - Fetch data from WebAPI using HTTPClient";
- }
- <style>
- table {
- font-family: arial, sans-serif;
- border-collapse: collapse;
- width: 100%;
- }
- td, th {
- border: 1px solid #dddddd;
- text-align: left;
- padding: 8px;
- }
- tr:nth-child(even) {
- background-color: #dddddd;
- }
- </style>
- <div style="padding:10px ; align-content:center">
- <fieldset>
- <legend style="font-family:Arial Black;color:blue">Get Data From Web API Using HTTPClient</legend>
- </fieldset>
- </div>
- <div id="updatePanel" style="width:90%; padding:10px; margin:0 auto;">
- <table class="table table-responsive table-striped table-bordered">
- <thead>
- <tr>
- <th style="background-color: Yellow;color: blue">Full Name</th>
- <th style="background-color: Yellow;color: blue">Email</th>
- <th style="background-color: Yellow;color: blue">City</th>
- <th style="background-color: Yellow;color: blue">Country</th>
- </tr>
- </thead>
- <tbody>
- @foreach (var i in Model)
- {
- <tr>
- <td>@i.FirstName @i.LastName</td>
- <td>@i.EmailID</td>
- <td>@i.City</td>
- <td>@i.Country</td>
- </tr>
- }
- </tbody>
- </table>
- </div>
- @model IEnumerable<Entities.Employee>
- @foreach (var i in Model)
- {
- <tr>
- <td>@i.FirstName @i.LastName</td>
- <td>@i.EmailID</td>
- <td>@i.City</td>
- <td>@i.Country</td>
- </tr>
- }
- Introduction to HttpClient ASP.NET Web API.
- Steps for retrieving data from the database using HttpClient.

Alice NguyenPosted Dec 5, 2018, 3:09 AM
Thank Satyaprakash Samantaray for sharing. So great
Arun Kumar SinghPosted May 22, 2018, 12:22 AM
Just awesome bro keep it up
Manav PandyaPosted May 4, 2018, 3:23 AM
Thanks for such stuff brother Satyaprakash Samantaray
Sachin SboaPosted May 2, 2018, 11:55 AM
Nice job satya... this web api series very helpful
Bhavesh JadavPosted May 1, 2018, 8:37 AM
Very good article for me, thanks for sharing it.