NANCY Sinatra

An instance of Ruby's influence in .NET

Presented by David Roberts / @davidroberts63

Sinatra

A DSL for quickly creating web applications in Ruby.

Nancy

Lightweight low ceremony web application framework
get "/sayhello/{name}" do
  "Hello " + {name}
end
public class HomeModule : NancyModule
{
  public HomeModule()
  {
      Get[″/sayhello/{name}″] = 
            input => return ″Hello ″ + input.Name;
  }
}

Tweet App

Using ScriptCS

scriptcs -install ScriptCs.Nancy;
'Require<NancyPack>().Get("/",_=>"Hi").Host();'|Out-File s.x;
scriptcs s.x #dropsmike @NancyFx @scriptcsnet

Runs just about anywhere

Uses its own Request/Response objects.
Not dependent on ASP.NET


  • OWIN
  • Self Host
  • ASP.NET
  • Nginx, RaspberryPi ...

WCF

Ewwww.

Note, WCF NOT inspired by Ruby. Because Ruby wouldn't do that.

S. D. H. P.


  • It Just Works
  • Easily Customizable
  • Low Ceremony
  • Low Friction


Super Duper Happy Path

Content Negotiation

Done automatically or controll it yourself

Get["/"] = p => return "Hello Jupiter!";
Get["/"] = parameters => {
  return Negotiate
    .WithModel(new RatPack {FirstName = "Nancy "})
    .WithMediaRangeModel("text/html", 
        new RatPack {FirstName = "Nancy for html"})
    .WithView("negotiatedview")
    .WithHeader("X-Custom", "SomeValue");
};

Easily Customizable


Custom Model Binding



public class CustomModelBinder 
  : Nancy.ModelBinding.IModelBinder 
{ . . . }
					

Easily Customizable

Custom View Engine

public class CustomViewEngine 
  : Nancy.ViewEngines.IViewEngine
{ . . . }
  • Super Simple
  • Razor
  • NDjango
  • Nustache
  • Spark
  • DotLiquid
  • Veil
  • Parrot
  • NHaml
  • HandlebarsJs
  • Markdown

Testability

Test the whole Nancy pipeline quickly with the Browser object.

public void Should_return_status_ok_when_route_exists()
{
 var bootstrapper = new DefaultNancyBootstrapper();
 var browser = new Browser(bootstrapper, 
       defaults: to => to.Accept(″application/json″));

 var result = browser.Get(″/″, 
       with => { with.HttpRequest(); } );

 Assert.Equal(HttpStatusCode.OK, result.StatusCode);
}

Diagnostics

  • Information (== PHPINFO)
  • Static Configuration
  • Request Tracing
  • Interactive Diagnostics (customizable)

!the_beginning


teapotcoder.com

@davidroberts63

twitter, github, bitbucket, jabbr, IRC

NancyFx.org