REST Raiding. Nancy

 
event

The first contender has a lovely woman’s name: Nancy.

Get it!

Getting Nancy up and running is as straightforward as it can be: create a Visual Studio Web Application project and install the nuget package. That is it.

Documentation

If the homepage was both elegant and useful, the documentation page is mouth watering. Simple and straight to the point. I was pleasantly surprised by the quality and the general vibe of the project.
This one is for those that claim that all OSS projects are a waste of time and lack documentation. Watch and cry.

The services

The service that returns all snapshots will be hosted in the url /catalogs and the one that returns the single detail in /catalogs/{catalog_name}. Resources are accessed in Nancy via modules (inheritors of NancyModule). Modules specify the URL and the HTTP method using a very neat indexer-function syntax. Since both services are related by the base URL, Nancy allows them to be grouped in the same module. No more configuration. As DRY and simple as it gets.

The /catalogs service is as simple as it gets as no argument is needed and uses no globalization. The only thing to point out is the Response.BarebonesContentNegotiation() method. Since Nancy does not implement (yet) any content negotiation or dynamic response formatting I developed a coarse method to find out whether to return XML or default to JSON, using the Nancy extensions .AsXml() and .AsJson(). It is clumsy and incorrect to an extreme, but since it is a POC I am not that embarrassed Winking smile

For the /catalogs/{catalog_name} service there are some more interesting points. The first one is how route parameters are passed: that is what the function argument parameters is for. It cleverly uses dynamics to give access to the parameters by name. The other thing to point out is how the language is retrieved by extending the  Nancy type Request. It should be easy enough since it exposes the Headers.AcceptLanguage property. Unfortunately, the language string is not parsed and weighed as it should be (yet) and the whole language string is passed in the first element of the collection. Well, since I am hosting Nancy in ASP.NET, I have all the “power” of the ASP.NET pipeline, and the weighed collection of languages can be accessed from the current HttpRequest.UserLanguages property (as long as testability is not a big concern).

In the above snippet one can see the clever use of dynamics to access query-string values (via a dynamic property with the key of the element that gives access to an object that let know whether the key has a value and which value is that).

Opinion

I have to admit I did not expect Nancy to be in such a good shape. The site looks gorgeous, documentation is available, community is growing and getting it up and running was a pleasure.

And what is more important: what they preach about low ceremony and simplicity cannot be more true. Most of the decisions make sense and look clean and approachable.

Its simplicity and youth make it lack some features I needed out of the box (such as dynamic response formatting) but I am certain that they will come.

Definitely a strong candidate to be taken very seriously.


UPDATE: I mentioned that how the Accept-Language header was not parsed correctly. Well, I created a new issue in their GitHub repository. Literally, minutes passed until I received feedback and hours until a pull request was issued with the fix. That, dear readers, is just another testimony of how awesome OSS can become.
share class ,