BT

ASP.NET Web API – A New Way to Handle REST

by Jonathan Allen on Feb 23, 2012 |

Web API is the first real alternative to WCF that .NET developers have seen in the last six years. Until now emerging trends such as JSON were merely exposed as WCF extensions. With Web API, developers can leave the WCF abstraction and start working with the underlying HTTP stack.

Web API is built on top of the ASP.NET stack and shares many of the features found in ASP.NET MVC. For example, it fully supports MVC-style Routes and Filters. Filters are especially useful for authorization and exception handling.

In order to reduce the amount of mapping code needed, Web API supports the same Model binding and validation used by MVC (and soon to be released NET Web Forms 4.5). The flip side of this is the content negotiation features. Web API automatically supports XML and JSON, but the developer can add their own formats as well. The client determines which format(s) it can accept and includes them in the request header.

Making your API queryable is surprisingly easy. Merely have the service method return IQueryable<T> (e.g. from an ORM) and it Web API will automatically enable OData query conventions.

ASP.NET Web API can be self-hosted or run inside IIS.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

first real alternative by steven casey

unless openrasta is a figment of my imagination, doesn't it qualify as the "first real alternative". or maybe even servicestack? would be nice if the article was a balanced one and not just a press release from MS.

Re: first real alternative by Jonathan Allen

OpenRasta is not a viable project at this time. Right now it is just a dumping ground for someone’s experimental code. There are some interesting ideas in there, but there is also a lot of junk. In one file I see a logging interface that has no documentation, an interface with a type parameter it ignores, and an interface that is completely empty.

Then there is the strange decision to reinvent stuff that is unrelated to the core functionality of OpenRasta. This shouldn’t be shipping with its own IoC container, it shouldn’t even need one. That is something that the developers should decide for themselves. And then there aforementioned logging API, which completely ignores .NET’s official API (TraceListener) as well as the popular alternatives. Heck, it even has its own package manager that simply wraps NuGet.

The whole love/hate relationship with ASP.NET is very confusing, but not as confusing as their project pages. When I go to get the bits from their home page they aren’t even sure if I’m supposed to be using OpenWrap or NuGet. And the only link they provide is to their “stable” repository, which really contains the obsolete branch. (Which in a way means that it is stable.)

I like writing about open source alternative’s to Microsoft’s .NET libraries. We need that competition to better the platform as a whole. But I can’t recommend something in this state. They need a lot of help to clear out the cruft and focus on the core feature set.

Re: first real alternative by Demis Bellot

First real alternative, Seriously?

www.servicestack.net has been Open Source and shipping on Production systems for over 4 years has amassed over 47 contributors and is the 11th most watched C# project on GitHub and yet it fails to meet your definition as an alternative?

What about it shipping the fastest text serializers for .NET? Like the kind StackOverflow had to switch to in order to get decent JSON performance:
blog.stackoverflow.com/2012/02/stack-exchange-o...

StackOverflow Careers also uses ServiceStack for all its Back Office web services, which makes use of all ServiceStack's components: JSON Serializer, C# Redis Client, OrmLite database since they are all lean libraries that work with clean POCOs and provide great performance:
www.servicestack.net/benchmarks/

Here's an answer on StackOverflow that compares ServiceStack vs WebApi - I recommend getting familiar with the alternatives that *DO* exist before claiming otherwise in all sincerity.
stackoverflow.com/questions/9699083/servicestac...

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

3 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT