Chapter 7. The ASP.NET Web API
As your application’s client-side UI grows beyond a few simple AJAX requests, you may begin to
find that ASP.NET MVC’s JsonResult
-based
controller actions don’t quite meet the needs of an advanced AJAX frontend.
When this happens, it may be time to look for a more simple and elegant way
to handle advanced AJAX requests. It may be time to start using the
ASP.NET Web API.
The ASP.NET Web API Framework leverages both web standards—such as HTTP, JSON, and XML—and a standard set of conventions to provide a simple way to build and expose REST-based data services. From an architectural standpoint, the ASP.NET Web API is very similar to ASP.NET MVC in that it leverages some of the same core concepts, such as routing, controllers, and even controller action results. It uses these concepts, however, to support a very different set of scenarios: scenarios that involve working with data as opposed to generating HTML markup.
This chapter gives you a basic introduction to the ASP.NET Web API Framework, showing you how to create and expose ASP.NET Web API services, then consume those services via AJAX from a browser.
Building a Data Service
Adding an ASP.NET Web API controller to your application is almost exactly like adding an ASP.NET MVC controller. The following sections walk you through the process by showing how you can add a Web API controller to the Ebuy reference application.
Before you begin, you’ll need a folder in which to store your new Web API controller. ...
Get Programming ASP.NET MVC 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.