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 ...

Get Professional 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.