left-icon

NancyFX Succinctly®
by Peter Shaw

Previous
Chapter

of
A
A
A

CHAPTER 2

What is NancyFX?

What is NancyFX?


Nancy is a microframework for the .NET platform. Heavily inspired by the Sinatra framework available in the ruby world, Nancy provides a low-ceremony, aggravation-free toolkit for "web enabling" your applications, irrespective of which .NET language you use to build them.

You'll notice that I use the term “web enabling,” and this is with good reason. Nancy is not just a web application framework designed to build web sites or API endpoints; it is a complete framework that can be used to add HTTP-based server facilities to everything from simple console mode applications right through to large-scale enterprise sites running on platforms such as Umbraco and ASP.NET MVC.

Nancy can be hosted in traditional scenarios, such as classic IIS7 with ASP.NET, and it can be self-hosted. Self-hosting is particularly interesting because it means normally invisible applications (such as Windows services) can now have a web interface attached to them for administration purposes.

Nancy can also be built on, and will happily run on, Linux and Unix systems under the Mono framework. This means that you can (or at least should be able to) run your Nancy-enabled code on Android and Mac OS. I'm going to stop short of saying you can definitely do this with those two operating systems, however, since I personally have never tried using Nancy on either Android or Mac OS.

This book will primarily focus on running Nancy on the Windows platform using Visual Studio. However, I’ve tried most of the code you'll be introduced to on Ubuntu Linux and on a Raspberry PI running the "Raspbian" version of Linux, and both have been shown to work without issue.

You might already by asking yourself whether you should use Nancy instead of another framework, such as MVC, ASP, Ember, or ServiceStack. How do you know which is best? The truth is that there is no "best framework" that suits every task you may have to address during your work as a software developer—you just choose the best framework for the task at hand.

What I do know, however, is that Nancy offers a large chunk of functionality that is incredibly easy to pick up and use.

As way of a comparison, when I first found out about Nancy (way back in 2011, about version 0.8 or 0.9), I learned everything I needed to know and got up and running with it in about half a day. Several years after I first used it, ASP.NET MVC is still an on-going learning process.

Nancy's capabilities at a glance

So what can Nancy do? Here is a short list of what’s built into the basic framework:

  • Rest-based routing
  • View page substitution with a built-in, simple view engine
  • Static file serving
  • Multitenancy service hosting
  • Rest API authentication (basic, forms and token-based)
  • Flexible model-binding
  • Multi-format content negotiation
  • Cryptographic key and phrase generation
  • SSL certificate-handling
  • Async task-handling
  • Dependency injection

This list is just the tip of the iceberg; everything you see mentioned here can all be overridden with custom code because of the modular nature of the toolkit. You can easily plug-in your own dependency injection container, or provide your own extended authentication schemes.

With the extra third-party assemblies that are available to add to Nancy, you get the following too:

  • OAuth-based authentication
  • Connection to third-party diagnostic and logging providers (such as Glimpse and ELMAH)
  • Cross-platform integration to things like NGINX, Apache, and other non-Windows application stacks
  • Anything else you can imagine and write an adapter for

That last point is not just there for effect—you can easily override anything you want (or need) to. Every interface in Nancy is exposed publicly, and for the best part wired up automatically, meaning all you generally need to do is write a class that implements a given interface, and Nancy will find it and do the rest.

The last major trick that Nancy has is hosting. Nancy can be hosted in multiple scenarios; the basic list on the Nancy Wiki looks like this:

  • ASP.NET
  • Windows communication foundation
  • Microsoft Azure
  • OWIN
  • Self-hosting (standalone apps)
  • Umbraco
  • NGINX
  • Anything that supports FastCGI

Like with everything else, there's an interface you can implement to provide your own hosting providers if needed.

Summary

In this chapter, you learned what the NancyFX framework is and what its capabilities are. In the next chapter, you'll learn a bit more about the back story behind Nancy’s creation, as well as a little bit more about its ethos, ideals, and the "super-duper-happy-path."

Scroll To Top
Disclaimer
DISCLAIMER: Web reader is currently in beta. Please report any issues through our support system. PDF and Kindle format files are also available for download.

Previous

Next



You are one step away from downloading ebooks from the Succinctly® series premier collection!
A confirmation has been sent to your email address. Please check and confirm your email subscription to complete the download.