November 20, 2016

Demystifying Nancy

Demystifying Nancy REST API

I have came across many questions from developers and budding enthusiasts about what is Nancy Fx all about. I want to make it more informative on the topic that is less known to everyone. So, let us dig into it.



Why the name NancyFx? 


At first when I heard the name NANCY, besides knowing what technically it is? I was more eager to know that why the name NANCY ;). Then I came to know that NANCY was made out of the inspiration from Sinatra framework for Ruby and, hence, Nancy was named after the daughter of Frank Sinatra :) Many people wonder what Fx in NancyFx means so here it is-> it just means framework!

What is NancyFx? 


Nancy is a lightweight, low-ceremony, framework for building HTTP based services on .NET and Mono. The goal of the framework is to stay out of the way as much as possible and provide a super-duper-happy-path to all interactions. These are the lines that you might have come across till now.

Let me explain you clearly that what does this lines mean:
Lightweight:
1.    While .Net environment is a powerful application development framework, there is one significant downside. As a result of its enterprise background, most of the things are heavyweight for simple development tasks or prototyping, the area in which some other platforms excel like Nancy.

2.    Nancy is a therefore a light weight framework for building HTTP based services on .Net (also Mono). Here HTTP based services means that this framework can handle all standard HTTP methods like GET, POST, PUT, DELETE, HEAD etc... Everything in Nancy are "HOST's". A Host acts as a framework or adapter for a hosting environment and enables Nancy to run on existing technologies such as ASP.NET, WCF etc.
 Low Ceremony:
1.    As described above it doesn’t need any heavy design and complications to provide path and related stuffs as compared to the other API services, which will be later demonstrated in the page with code examples.
Hope, Now you are clear about what is Nancy.

 

Why use NancyFx?

When a new project comes along why should you automatically choose WebAPI? Yes, its Microsoft based so you may have more of your peers fluent already in that architecture but is there an alternative, a better alternative?I believe so and it’s called NancyFX. Your first reaction, what is so special about Nancy? I also believe you’ll ask what is wrong with ASP.NET MVC but maybe you should look at it differently. Nancy does not force you to adhere to the model-view-controller pattern, or any other pattern. It’s nothing more than a service endpoint responding to HTTP verbs. Making it ideal for building Websites, Web Services and APIs.That doesn’t mean you can’t apply the MVC pattern to Nancy. You can define Views and put them in a Views folder, create Models to return from your endpoints, and map requests to Models, just like you currently do with ASP.NET MVC.

Advantages of using preferring NancyFx
  1. Testing is easier, as the nancy provides a testing library through which you can test the full request and response cycle. Example is shown below.
  2. Dependency resolution is automatic:Nancy Fx provides us with a built in IOC container called TinyIOC which will find all your dependencies automatically.
  3. Extensions are always possible: As one of the SOLID principles say that always the code should be ready to extend and close to modification. Similarly, here we have better extension points.
  4. Terse Syntax & Less Ceremony – Nancy provides a nice terse syntax that does not get in the way of your application and leaves you to write your code. What I have found is that due to the terse syntax it encourages you to make your application code nice and neat too.
  5. Runs on Mono – As far as I’m concerned for MONO is when I’m developing a C# project or application in RaspberryPi. Hence, lot of API creation stuffs get easier if nancy runs on mono. You may find few posts for raspberry pi also in the upcoming posts.
  6. Navigation: / navigation option it use and a code content should be placed here
  7. No system.web file: Which again adds to the point for low-ceremony. As I described earlier nancy doesn’t like pomp and show, nancy loves to keep it very simple :D .  System.Web is the core DLL based in ASP.Net. It contains the whole kitchen sink of the framework so you get everything bundled into your application even if you only use 25% of the possibilities. Nancy is architected the other way in that there are numerous plugins that supply additional and alternative functionality. Nancy is also not bound to any specific implementation or framework and all requests and responses are built from the ground up allowing it to be loosely coupled and free. This also means that Nancy can run in the .Net client profile environments without the added requirement for .Net full profile that ASP.NET MVC does require.  


It was just basic info which was mandatory for you to know what NANCY is all about and you might be like:
Hold On...... The next post will be on creating your Own nancy based project...


Share:

0 comments :

Post a Comment

About Me

My Photo
Innovations and Passion are always been a part of my life. I do things only if I am passionate about it.

Popular Posts

Recent Posts

Total Pageviews