Consume Web API for CRUD operation
In the previous section, we created Web API with Get, Post, Put and Delete methods that handles HTTP GET, POST, PUT and DELETE requests respectively. Here, we will see how to consume (access) Web API for CRUD operation.
Here, we will consume our Web API (created in the previous section) in the following environments:
- Consume Web API in ASP.NET MVC
- Consume Web API in AngularJS
Consume Web API in ASP.NET MVC
To consume Web API in ASP.NET MVC server side we can use HttpClient in the MVC controller. HttpClient sends a request to the Web API and receives a response. We then need to convert response data that came from Web API to a model and then render it into a view.
The following figure illustrates consuming Web API in ASP.NET MVC.
Consume Web API in AngularJS
The following figure illustrates consuming Web API in client side framework using AJAX.
Learn how to consume Get, Post, Put and Delete methods of Web API in ASP.NET MVC and Angular in the next coming sections.