ASP.Net Web API is a powerful framework to retrieve data and to serve a broad range of clients. Once created, it can be used to access data within mobile applications too.
Web API's support developers to create RESTful services and the request is controlled by Controllers, which is similar to MVC controllers, but here the class will be derived from APIController when compared to MVC applications where it will be just Controller. This framework is really helpful to build HTTP based services and can very well control the returned data type to be json or XML.
If you are developing an application in MVC, it well suites to have Web API, as it is also based on routing concepts. More over, a given set of data can be accessed/modified through GET,PUT,DELETE etc.....
Now lets see how to create a simple Web API and invoke it through its URL....
I will create a new web API, by making the following choice : ASP.NET MVC 4 Web Application
After making the selection, make sure you select Web API option (with View Engine type being Razor).
Sample generated file structure below :
Main controller method inherits from APIController with default value being ValuesController. For tutorial purpose, I will create a new controller WebAPITestController that would generate and return data on invoking the method.
Now we have the controller ready. Since this is a regular Controller, we should extend the class with Sytem.Web.Http.ApiController to make it a Web API or we can select the following option when creating a controller, which will load with few empty basic method structures....
Click here to continue Creating a simple Web API....
No comments:
Post a Comment