Last active
December 21, 2015 08:59
-
-
Save mat-mcloughlin/6282141 to your computer and use it in GitHub Desktop.
A simple Nancy module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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