Chapter 8. Introduction to Web API

Web API was briefly mentioned in Chapter 1 because Visual Studio provides a template for automatically creating a Web API application. Web API allows you to build RESTful web applications. When using Web API in combination with the MVC architecture pattern, the Controller is often the entry point for the Resource (Model) being interacted with. The View with Web API is often a JSON or XML representation of the resource.

This chapter will demonstrate the Web API by enhancing the CRUD interaction with the authors that the previous two chapters have been focusing on. In this chapter, the listing of authors will be updated to perform the sorting and paging of authors via a Web API controller. Likewise, adding and editing an author will also interact with the same Web API controller. Previously, new HTML pages were returned, but when Web API is integrated, the HTML will be updated to use Knockout data bindings. These will be dynamically updated by the result of an AJAX request to a Web API endpoint, which will prevent full-page reloads.

Installing Web API

In Chapter 1, when the BootstrapIntroduction project was first created, Web API was not included. This means it now needs to be added via the NuGet Package Manager. If you wish to avoid the visual NuGet Package Manager, a console utility is also available. To install packages via the console, click Tools  NuGet Package Manager  Package Manager Console. In the console window, enter Install-Package ...

Get ASP.NET MVC 5 with Bootstrap and Knockout.js 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.