35

There is yet another framework for making HTTP calls called NancyFx. My question is what are the benefits of using it. I had quick look at the documentation:

https://github.com/NancyFx/Nancy/wiki/Documentation

and it looks like there is no outstanding feature due to which I would like to use this. What are the benefits of using it over WebHttp?

P.S: I keep reading about some strange phrase that keep repeating again and again "super-duper-happy-path". Is there anything apart from this "super-duper-happy-path"? Any real features implemented?

Jaggu
  • 6,298
  • 16
  • 58
  • 96
  • Works in mono, coventions like where the views are can be changed and routing is more like sinatra(ruby) and express(node.js) – roeland Feb 13 '14 at 20:37
  • NancyFx supports mono by design - so you can have EF6 + MySQL + NancyFx + Razor Views run on a Linux server using mono (had that runnung on mono 4 in a day...). Running ASP.NET MVC + EF6 on Linux is probably not that easy (if even possible jet). – Florian F Apr 29 '15 at 00:41
  • regardless the fact that this question was asked long time ago, http://dotnetfiddle.net/ provides sandbox for MVC which is built Nancy.. – Vlad Mysla Sep 09 '15 at 22:10

2 Answers2

48

It appears that it offers a different approach to defining "routes" (in the MVC sense) using lambdas to identify relative paths, arguments, and the implementation of the response.

Ultimately, the framework's key benefit is its expressiveness. In ASP.NET MVC the RouteTable is in the global.asax and the implementation is in the Control. It appears that in NancyFx, this is the pattern that prevails:

Action["/path"] = args => { return your_implementation_here; }

Example implementation:

Get["/products"] = id => { return GetRepository().Products.Single( q => q.Id == id); };

Explanation: An HTTP Get to the relative endpoint '/products' with an argument of 'Id' will return a single product from the repository where the Id argument matches the product's Id.

Expressive and Concise.

Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73
18

Disclaimer: I'm not a supporter of NancyFx :)
I'm in the process of evaluating if I should go with NancyFx or with ASP.NET Web API for the REST part of a project.

Apart from simplicity and expressiveness (which do have a value on their own, I think) already mentioned by GlennFerrieLive, I think I've grasped another couple of nice bits:

  1. It's easy to perform operations before and after any API request processing, in a kind of an Aspect Oriented way, so to say.

  2. By default the framework takes care of the accepted returned type, so it will appropriately convert output in JSON, XML, ...

  3. Lambdas implementing requests do not return actual filled data, but still in the form of a query. After that it's still possible to easily add filtering, sorting, and other operations before actually executing the query, hitting the DB, and returning the actual data.

  4. They have somehow wrapped the HttpRequest and made available to the developer an equivalent of that, with the difference that this new object is injected and you can of course substitute it with a mock ... So easier and cleaner testing.

Maybe some of those (all?) are already available in ASP.NET Web API and with the same ease, I don't know for sure.
HTH

superjos
  • 12,189
  • 6
  • 89
  • 134
  • 6
    ok, [this article](http://blog.jonathanchannon.com/2012/12/19/why-use-nancyfx/) says a lot more and better ... of course he's a supporter :) – superjos Mar 01 '13 at 01:40
  • 2
    do you also evaluate ServiceStack ? – vittore Apr 17 '13 at 09:17
  • no, I don't remember I knew about it. – superjos Apr 17 '13 at 11:00
  • 1
    Let me jump on your first point and say that before and after methods on each nancy module is WAY less flexible than Web API or MVC action filters. I'm in the process of evaluating nancy right now too. I like some things, but this is actually one of my main concerns with it. – BlakeH Sep 27 '13 at 14:11
  • I did not have a real experience on NancyFx, as in the end I opted for Web API (and MVC). I quite used filters/attributes, quite effectively in the end I think (my opinion of course), but before that I had to dig enough into the details of OnExecutingThis, OnExecutedThat, and so on. – superjos Sep 27 '13 at 16:59