Defining ASP.NET Web API

If there is one common denominator in digital communications today, it's the prevalence of HTTP. Not only do we have browsers in our PCs that have spoken it for more than two decades, many of us now carry significant computing power in our pockets every day in the form of smart phones. Applications frequently use HTTP and JSON as their communication channels to call home. A web application today probably isn't considered “done” until it offers some form of remotely accessible API.

When MVC developers ask me to give them the elevator pitch for Web API, I usually say: “ASP.NET MVC excels at accepting form data and generating HTML; ASP.NET Web API excels at accepting and generating structured data like JSON and XML.” MVC has flirted with providing structured data support (with JsonResult and the JSON value provider), but it still fell short in several ways that are important to API programmers, including:

  • Dispatching to actions based on HTTP verbs rather than action names
  • Accepting and generating content which may not necessarily be object oriented (not only XML, but also content like images, PDF files, or VCARDs)
  • Content type negotiation, which allows the developer to both accept and generate structured content independent of its wire representation
  • Hosting outside of the ASP.NET runtime stack and IIS web server, something which WCF has been able to do for years

An important part of this story, though, is that the Web API team went to great lengths to try to allow you to leverage your existing ASP.NET MVC experience with controllers, actions, filters, model binders, dependency injection, and the like. Many of these same concepts appear in Web API in very similar forms, which makes applications that combine MVC and Web API seem very well integrated.

Since it's an entirely new framework, ASP.NET Web API might warrant a book of its own. This chapter should help illustrate the similarities and differences between MVC and Web API and help you decide whether you want to start including Web API in your MVC projects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset