Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I know what a Web API is.
I've written API's in multiple languages (including in MVC3).
I'm also well practiced in ASP.Net.
I just discovered that MVC4 has "Web API" and without going through the video examples I can't find a good explanation of what exactly it IS.
From my past experience, Microsoft technologies (especially ASP.Net) have a tendency to take a simple concept and wrap it in a bunch of useless overhead that is meant to make everything "easier".
Can someone please explain to me what Web API in MVC4 is exactly? Why do I need it? Why can't I just write my own API?

share|improve this question
3  
Are you talking about the new Web API framework? That's separate from MVC. If that's what you mean, take a look at this blog post by Rick Strahl. –  Oded Aug 12 '12 at 16:58
1  
@Oded : You should put this as an answer. –  James P. Wright Aug 12 '12 at 19:32
    
The coolest thing about Web API (that I don't see listed anywhere in the accepted answer or the above link) is that if you return an IQueryable<> your web methods automatically support OData query syntax! -- In the general ASP.NET 4.5 Stack "Web API" and "SignalR" are "replacing" WCF (I am unsure if they are built on top of WCF or not, but WCF has been removed from all the block diagrams and replaced with "Web API" and "SignalR"). –  BrainSlugs83 Jun 17 '13 at 10:47
    
Why can't I just write my own API? With just regular ASP.NET MVC? You can. ASP.NET MVC Web API just gives you extra goodies to make it easier. Please see below. –  Jim G. Dec 14 '13 at 12:53

4 Answers 4

up vote 12 down vote accepted

ASP.NET Web API is a "non-opinionated" framework to build HTTP Service regardless of REST or RPC. It is Microsoft's best implementation of RFC 2616 (HTTP Spec).

Certainly you can build your own API but ASP.NET Web API:

  • Built based on the Russian Doll model which allows for lego-like modules to be added to the HTTP pipeline
  • Makes HTTP first class citizen so all common headers are strongly typed (not just name value) and helps with parsing them
  • Allows for both ASP.NET (IIS) hosting or self-hosting
  • supports content negotiation, media types, ...
  • Is Async from top to bottom
  • Uses a similar approach for clients with HttpClient
share|improve this answer

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices.

ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.

http://www.asp.net/web-api


EDIT:

Specifically, ASP.NET Web API includes:

  1. A streamlined ASP.NET pipeline with reduced overhead if you choose to host your service in IIS.
  2. HttpClient which makes it easier for a client to hook into the Web API.
share|improve this answer
    
I can read those things myself. My question is what's the point? What is so different in using Web API and using regular MVC but having JsonResults instead of ViewResults? –  James P. Wright Aug 12 '12 at 19:33
    
1. Before MVC 4, you could return a JSONResult without any issue. MVC 4 simply retains that capability, includes some other helper classes to make it easier, and streamlines the ASP.NET pipeline to reduce the overhead when you know that you won't need to return ViewResults. –  Jim G. Aug 12 '12 at 19:43
1  
Also, because it's a effectively an update for WCF Web API, you aren't wed to IIS. You can self-host an ASP.NET Web API service if you prefer. wcf.codeplex.com/… –  Jim G. Aug 12 '12 at 20:00

In short: ASP.NET Web API is making REST a first class citizen in .NET, which WCF was not really able to embrace. As you may know, ASP.NET Web API is a framework for building web APIs on top of the .NET Framework.

One of the biggest frustration we had as web developers was to face with the endless configurations with WCF. I mean, WCF is great but hasn’t been embraced the REST since the WCF Web API framework . There was something called REST Starter Kit but it ended up dead.

However, ASP.NET Web API is a next generation framework that makes it easy to build HTTP services that reach a broad range of clients, such as browsers and mobile devices. It is an ideal platform for building RESTful applications on the .NET Framework. For more information and great blog posts, visit ASP.NET Web API bloggers page

share|improve this answer
    
If you research the history of Web API, it began in WCF. –  SASS_Shooter Jan 4 '13 at 18:06
    
Well, it is a lightweight replacement of it with important features to ease the configuration and streamline app development. –  Yusubov Jan 4 '13 at 18:36
    
@Yusobov: This is not quite true - There are also the WCF Data Services which are quite good at building Odata-compatible REST apis. I've been using it in a production environment and it really works well once it's set up. The only problem with that is that is much harder to set up than an ASP.NET Web API. –  Adrian Grigore Feb 7 at 15:21

The new Web API from Microsoft is, as its name suggests all about writing APIs that are web accessible, with a bent on REST.

Rick Strahl recently blogged about it and has a good analysis on when to use MVC vs Web API.

Things like built in content negotiation, several built in formats and more.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.