ASP.Net Web API is a framework for creating web services that
exposes data services to a broader range of clients including mobile devices,
tablets, browsers and traditional desktop applications. Any mobile like Windows
Phones, iPhones, Android or any browser can communicate to Web API if they are
able to handle HTTP request/response.
ASP.Net Web API communicate with HTTP/HTTPs and are used for creating fully
resource oriented services that return JSON, XML, or any other requested format
the web supports. The purpose of Web API framework is to generate HTTP services
that reach more clients by generating data in raw format that is in XML or JSON
format. Web APIs can provide data services to mobile apps and browsers.
ASP.Net Web API uses all the features of HTTP like URIs, request/response
headers, various content formats caching, versioning and there is no need to
define any extra configuration settings for different devices. The data will be
traveling to and fro from the server to the client because the capabilities of
the service are mapped to the URIs and protocols. At the client side there is no
need to create a proxy as client application and can directly retrieve and
process the data. We are able to perform various operations on these resources
with the help of HTTP protocols.
The basic CRUD operations are mapped to the HTTP protocols in the following
manner:
-
GET: This is the Retrieve part of CRUD operations. This will be used to retrieve the required data from the remote resource.
-
POST: This is Create part of the CRUD operation. This will create a new entry for the current data that is being sent to the server.
-
PUT: This is the Update part of the CRUD operation. This protocol will update the current representation of the data on the remote server.
-
DELETE: This is Delete part of the CRUD operation. This will delete the specified data from the remote server.
Features of ASP.NET WEB API
-
It supports strong URL routing to produce URLs using similar MVC style of routing.
-
It supports content negotiation which is the process of selecting the best representation for a given response when there are multiple representations available, based on Accept headers for request and response serialization.
-
The Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML or whatever format we want to add as a MediaTypeFormatter
-
It has automatic support for OData.
-
It can be hosted with in the application or on IIS.
-
It supports MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection that makes it more simple and robust.
-
It supports self-hostable in non-Web applications.
-
These are testable using testing concepts similar to MVC.
Features of ASP.NET WEB API 2 - Web API 2 now supports attribute routing as well with convention routing.
- CORS is a mechanism that allows a web page to make an AJAX call to a domain other than the domain which actually rendered that specific web page. CORS is compliant with W3C standards and is now in ASP.NET Web API 2.
- ASP.NET Web API 2 comes with a new self-hosting package i.e. OwinSelfHost which defines a standard interface between .NET web servers and web applications. The goal of the OWIN interface is to decouple server and application, encourage the development of simple modules for .NET web development, and, by being an open standard, stimulate the open source ecosystem of .NET web development tools.
- ASP.NET Web API 2 has added support for $expand, $select, and $value options for OData (open Data Protocol). By using these options, we can control the representation that is returned from the server.
- It supports IHttpActionResult that help us to construct and format response message by giving instructions which we want the Web API to follow.