ASP.Net Web API
A Web API stands for Application Programming Interface for both web server and web browser.
Web API Programming is a programming interface to a defined request-response message system, typically expressed in JSON or XML data format, which is exposed via the web over HTTP based server.
Read more articles on How to implement WCF Restful Service - .Net Framework 4.0, Consume Restful WCF service in ASP.NET Web Application Examples, How to Consume a WCF RestFul Service in jQuery via AJAX Call.
Web API in ASP.Net MVC
ASP.Net Web API is a framework for building web APIs on top of the .Net Framework. It is also a powerful platform for building APIs that expose services and data. HTTP is simple, flexible, and ubiquitous.
Almost any platform that you can think of has an HTTP library, so HTTP services can reach a broad range of clients, including browsers, mobile devices, and traditional desktop applications. It is very similar to ASP.NET but it's not a part of MVC framework.
Why to use Web API?
If you like to expose your service data to the browsers and as well as all mobiles, iphone and tablets apps in fast and simple way, you should have an API which is compatible with browsers and all these devices. For example twiiter, facebook and Google API.
|Use of Web API|
ASP.NET Web API is an ideal platform for building RESTFUL (Representational State Transfer) applications on the .NET Framework. There are following other things that tells why to choose Web API?
- It is an open source framework
- Everything is resource and it is identified by a unique identifier (URI)
- It is only based on HTTP and easy to define, expose and consume in a RESTful way.
- If we need a Web Service and don’t need SOAP, then ASP.Net Web API is best choice on top of existing WCF message pipeline.
- It supports convention-based CRUD Actions since it works with HTTP verbs GET,POST,PUT and DELETE.
- Responses have an Accept header and HTTP status code.
- It can be hosted with in the application or on IIS.
- It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection that makes it more simple and robust.
Use Web API If?
- Only working with HTTP
- Want RESTful endpoints
- Don’t need multiple protocols
- Don’t expose SOAP endpoints
- Want Simple Configuration
Web API Media Types & Media Formats
- Built in support for XML, JSON, form-URL encoded data
- Can be extended with custom Media Formats
Web API Parameter Bindings
- From Query-String: Using Model Binding
- From Body: Using different data formats like JSON, XML.
Conclusion : It was fun in learning and writing an article on ASP.Net WebAPI. I hope this article will be helpful for enthusiastic peoples who are eager to learn and implement some interesting stuffs in new technology.
Please feel free to comment your opinion about this article or whatever you feel like telling me. Also if you like this article, don't forget to share this article with your friends.