Chapter 24. ASP.NET Web API

 

This chapter covers

  • Deciding to use Web API
  • Understanding the new runtime
  • Introducing the ApiController
  • Developing HTTP web services

In this chapter, we’ll use the Guestbook application that was introduced in chapter 2 as a foundation on which to build some Web API web services. Remember that the Guestbook is a simple application that will allow users to post their name and a message to the site, and to see the messages posted by other users. The application exposes these functions on normal web pages. Web API is a new way to write simple HTTP web services. We’ll re-implement the listing and posting features of the Guestbook application using Web API web services.

24.1. What is Web API?

Web API is a new web application runtime that builds on the lessons and patterns proven in ASP.NET MVC. Using a simple controller paradigm, Web API enables a developer to create simple HTTP web services with very little code and configuration.

You could ask a very reasonable question: why do we need a new web services framework? Doesn’t the Microsoft development stack already include a popular and widely compatible Simple Object Access Protocol (SOAP) technology? And haven’t ASMX web services existed since ASP.NET was released? And doesn’t Windows Communication Foundation (WCF) already support the most flexible and scalable web service infrastructure around? Web services are commonplace, and developers understand them. Why Web API?

24.1.1. Why Web API?

24.2. Adding web services to the Guestbook application

24.3. Web API alternative

24.4. Summary