ASP.NET Web API Basics
ASP.NET Web API Basics
Join the DZone community and get the full member experience.Join For Free
What is Web API? ASP.NET Web API is a framework for building web API on the top of .NET framework. It’s a framework for building and consuming web services that can be use at broad range of clients like browsers,tablets phones etc. You can expose JSON or XML whatever you want to use.
Why use Web API? Think about a situation where a jQuery script that is making a ajax request and we need some thing who can expose data from the server to the client at that time WEB API can be very handy you can expose server data in XML or JSON form and you can make that call with simple http request. No lengthy code required to call WEB API.
It has following features which could be really useful and handy whenever we are creating service or API for our web application.
- Modern HTML Programming Model:We can directly access and manipulate http web request with strongly type HTTP model. The same programming model is available on the any HTTP client.
- Full Support for routes: Web API supports the full set of route capabilities that you have in ASP.NET MVC and ASP.NET Web forms 4.0.
- Exception Handling : It has full support for exception handling and exception filters so you can handle error in much better way.
- Authorization: It has various support for authorization. You just need to add [Authorise] on the controller and actions that is needed by it.
- Custom Validation: Just like model validations we need to add validation attributes to model and our custom validation is ready.
- Content Negotiation: The client and server can work together to determine the right format for data being returned from API. XML and JSON support are directly provided. You can extend this support by adding your own formatters.
How to install Web API: If you are having Visual Studio 11 Beta installed on your machine then it will directly will be available as built in project template but If you are using Visual Studio 2010 then you need to install ASP.NET WEB API and ASP.NET 4.0 via web platform installer. You can get ASP.NET Web API installer from the following link.
That’s it. Hope you like it. Stay tuned more updates.Till then Happy Programming!!
Published at DZone with permission of Jalpesh Vadgama , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.