Skip to content

Instantly share code, notes, and snippets.

@mat-mcloughlin
Last active December 21, 2015 08:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mat-mcloughlin/6282141 to your computer and use it in GitHub Desktop.
Save mat-mcloughlin/6282141 to your computer and use it in GitHub Desktop.
A simple Nancy module
using Nancy;
using Nancy.ModelBinding;
public class TurtleModule : NancyModule
{
public TurtleModule() : base("/turtle")
{
// Note: arguments can be named anything.
Get["/"] = arguments =>
{
return "Teenage Mutant Ninja Turtles";
};
Get["/{name}"] = arguments =>
{
// Note: the arguments are case insensitve. arguments.name is also fine
return "Hello " + arguments.Name;
};
Post["/"] = arguments =>
{
var model = this.Bind<Turtle>();
return model.Name + " wears a " + model.MaskColour + " mask";
};
}
}
public class Turtle
{
public string Name { get; set; }
public string MaskColour { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment