Skip to content

meadiagenic/Nancy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Meet Nancy

Nancy is a lightweight web framework for the .Net platform, inspired by Sinatra. Nancy aims to deliver a low ceremony approach to building light, fast web applications.

Features

  • Built from the bottom up, not simply a DSL on top of an existing framework. Removing limitations and feature hacks of an underlying framework, as well as the need to reference more assemblies than you need. keep it light
  • Abstracted away from ASP.NET / IIS so that it can run on multiple hosting environments (see below for planned OWIN support), such as (but not limited to) ASP.NET, WCF, Mono/FastCGI and more (ASP.NET and WCF currently supported)
  • Ultra lightweight action declarations for GET, HEAD, PUT, POST and DELETE requests
  • View engine integration (Spark and Razor in development, read below how to help add more to the list)
  • Powerful request path matching that includes advanced parameter capabilities. The path matching strategy can be replaced with custom implementations to fit your exact needs
  • Easy response syntax, enabling you to return things like int, string, HttpStatusCode and Action elements without having to explicitly cast or wrap your response - you just return it and Nancy will do the work for you

Usage

Set up your web.config file:

<httpHandlers>
    <add verb="*" type="Nancy.Hosting.NancyHttpRequestHandler" path="*"/>
</httpHandlers>

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
        <add name="Nancy" verb="*" type="Nancy.Hosting.NancyHttpRequestHandler" path="*"/>
    </handlers>
</system.webServer>

Start adding your Nancy modules containing your actions:

public class Module : NancyModule
{
    public Module()
    {
        Get["/"] = x => {
            return "This is the root";
        };
    }
}

Start your application and enjoy! Swap out Get with either Put, Post or Delete to create actions that will respond to calls using those request methods.

If you want to get fancy you can add parameters to your paths:

public class Module : NancyModule
{
    public Module()
    {
        Get["/greet/{name}"] = x => {
            return string.Concat("Hello ", x.name);
        };
    }
}

The {name} parameter will be captured and injected into the action parameters, shown as x in the sample. The parameters are represented by a dynamic type so you can access any parameter name straight on it as a property or an indexer. For more information on action parameters please refer to the Nancy introduction post over at my blog on [ElegantCode](http://elegantcode.com "Visit ElegantCode).

Nancy also supports the idea of module paths, where you assign a root path for all actions in the module and they will all be relative to that:

public class Module : NancyModule
{
    public Module() : base("/butler")
    {
        Get["/greet/{name}"] = x => {
            return string.Concat("Hello ", x.name);
        };
    }
}

Notice the base("/butler") call to the NancyModule constructor. Now all action paths that are defined in the module will be relative to /butler so in order to greet someone you could access /butler/greet/{name}, for example /butler/greet/thecodejunkie

Help out

There are many ways you can contribute to Nancy. Like most open-source software projects, contributing code is just one of many outlets where you can help improve. Some of the things that you could help out with in Nancy are:

  • Documentation (both code and features)
  • Bug reports
  • Bug fixes
  • Feature requests
  • Feature implementations
  • Test coverage
  • Code quality
  • Sample applications

TODO / Design decisions

  1. Make Nancy run on the Open Web Interface for .NET
  2. Enable IoC container integration so that Nancy modules can have dependencies that are resolved at runtime
  3. Ship a nice set of Response formatters, such as json, xml and others
  4. Request and Response interception to enable rich middleware capabilities such as caching and logging
  5. View engine integration. Spark and Razor are planned. Looking for contributors for Haml, NDjango and other popular view engines (contact me if you want to help out!)
  6. Self-composing framework - make Nancy use an internal IoC to compose the framework at runtime. Increasing modularity of the framework and the ability to swap out parts
  7. NuGet presence

View Engines

There is a rich set of view engines in the .net space and most of them have been design in such a away that they are framework agnostic, all that is needed is a bit of integration work to get it running in Nancy.

  • Static - The static view engine serves up any static textfile (which includes html files) you have in your project. It is invoked with the virtual path of the file you want to serve. The current implementation serves as a proof of concept and needs more work to be stable
  • Razor - With this view engine you can use views with Nancy. The current implementation serves as a proof of concept and needs more work to be stable
  • Spark - Working spike waiting to be cleaned up and pushed into the repository
  • NDjango - The current implementation serves as a proof of concept and needs more work to be stable
  • NHaml - The current implementation serves as a proof of concept and needs more work to be stable
  • WebForm - In need of integration help

Contributors

Nancy is not a one man project and many of the features that are availble would not have been available without the awesome contributions from the community!

  • Andy Pike
  • Graeme Foster
  • Karl Seguin
  • Jason Mead
  • Jeremy Skinner
  • João Bragança
  • John Downey
  • Mindaugas Mozuras
  • Pedro Felix
  • Phil Haack
  • Steven Robbins

Copyright

Copyright © 2010 Andreas Håkansson

License

Nancy is licensed under MIT. Refer to license.txt for more information.

About

A Sinatra inspired web framework for the .NET platform (this is the authoritative fork)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%