Benefits of using NancyFx?

29,672

Solution 1

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.

Solution 2

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

Share:
29,672
Jaggu
Author by

Jaggu

Updated on July 24, 2022

Comments

  • Jaggu
    Jaggu almost 2 years

    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?

  • superjos
    superjos over 11 years
    ok, this article says a lot more and better ... of course he's a supporter :)
  • vittore
    vittore about 11 years
    do you also evaluate ServiceStack ?
  • superjos
    superjos about 11 years
    no, I don't remember I knew about it.
  • BlakeH
    BlakeH over 10 years
    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.
  • superjos
    superjos over 10 years
    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.