ASP.NET Web API
In this tutorial, I am going to explain you about ASP.NET Web API and Why should we should we use ASP.NET Web API.
ASP.NET Web API Released by ASP.MVC 4. ASP.NET Web API provides us a framework for building HTTP Services that can be consumed by verity of clients like browser, mobiles, iPhones, and tablets. ASP.NET Web API is a perfect platform for building for developing RESTful applications on .NET. Since ASP.NET Web API contains all features like ASP.NET MVC Routing, Controllers, Action Results, filters, modal binders, IOC container or Dependency Injection. So ASP.NET Web API analogous to ASP.NET MVC. An ASP.NET Web API can be used with MVC, ASP.NET Web Form Application or as Stand-alone web application because it is not a part of MVC Framework. It is a part of core ASP.NET.
You can learn Introduction to ASP.NET MVC here.
Why Use Web API?
In Today’s life, customers are getting smarter and smarter because they are using mobiles, tablets, iPhone. And these devices are using different apps that make life easier. These means that we are moving from web towards apps world. So a web-based application is not good enough to reach its customer. So if you want to expose your service data to browsers as well as modern devices you should have an API that is compatible with browsers as well as all devices.
- Provides First-class modern programming modal.
- Rich support for formats and HTTP content negotiation.
- Flexible hosting.
- Lightweight, testable, scales.
- We can develop an HTML5 Application that needs a service layer
- A Mobile Application that needs a service layer
- When we want to develop a client-server application that needs a service layer.
Features of Web API?
- It works with HTTP verbs GET, POST, PUT and DELETE that is why it supports convention-based CRUD actions.
- Responses have an Accept header and HTTP status code.
- Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.
- It may accept and generates the content which may not be object-oriented like images, PDF files etc.