PRESENTATION OUTLINE
Inspired by a framework called Sinatra
(note the word inspired)
These boots are made for Walkin'
Hardest problem in programming is naming things
It's Easier and More Funner
Built from the ground up
Not a simple DSL on top of an existing framework
Run Anywhere
- ASP.NET
- IIS
- Self Host
- WCF
- Any OWIN (including Mono)
Out of the Box
TinyIOC
(or use your favorite IOC)
Automatic Dependency Resolution
Ultra light Action Declarations
View Engines
- Razor
- Spark
- Super Simple View Engine
- dotLiquid
- Markdown and many more...
Powerful request path matching
Minimal Configuration Required
Nancy Modules
- Define behavior using routes and actions
- Accesses the current request and context
- Helpers for building responses and rendering views
- Model bindings
- Security and Authentication
You can have as many modules as you like in your application, just as long as there is at least one and that it has at least one route defined
DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH
Patterns
- Literal segments - /some/literal/segments
- Capture segments - /{name}
- Capture segments (optional) - /{name?}
- Capture Segments (optional/default) - /{name?unnamed}
- RegEx Segment - /(?[\d]{1,2})
More Patterns
- Greedy Segment - /{name*}
- Greedy RegEx Segment - ^(?[a-z]{3,10}(?:/{1})(?[a-z]{5,10}))$
- Multiple Captures Segment -- /{file}.{extension} or /{file}.ext
Model Binding
Out of the box, Nancy ships with two body deserializers, one for JSON and one for XML. The model binder will use the Content-Type HTTP header to determine which deserializer should be used for the attached request body.
Click to Edit
Out of the box, Nancy ships with two body deserializers, one for JSON and one for XML. The model binder will use the Content-Type HTTP header to determine which deserializer should be used for the attached request body.
Blacklist Properties
Out of the box, Nancy ships with two body deserializers, one for JSON and one for XML. The model binder will use the Content-Type HTTP header to determine which deserializer should be used for the attached request body.
Deserializing rich request body payloads
- Nancy ships with JSON and XML Deserializers
- Content Type determines which to use
- You can add your own body deserializers
Out of the box, Nancy ships with two body deserializers, one for JSON and one for XML. The model binder will use the Content-Type HTTP header to determine which deserializer should be used for the attached request body.
BootStrapper
The bootstrapper is also responsible for some of the magic that you are treated to when working with the framework, such as automatic discovery of modules, custom model binders, dependencies and much more.
The bootstrapper is responsible for some of the magic that you are treated to when working with the framework, such as automatic discovery of modules, custom model binders, dependencies and much more.
Locating Views
- Look in the root
- Look in the views folder
- Look in the module path folder
- Look in folder with module name
- Look in views folder with module name
View from Model Type
- Same rules but use the model name as view name
- If type ends in "Model" it is stripped off
- Customer model type -> Customer view name
- CustomerModel model type -> Customer view name
Super SimPle View Engine
- Built in, no additional dependencies
- Has layouts, partials, models, conditions, iterations
- Serves up .html and .sshtml
- No expression evaluation
- Can only reference properties of models
TL;DR: stick stuff in /Content .. done.
Diagnostics
- Built-in to the main assembly
- http:///_Nancy/
- Fast, extensible and cross-browser compliant.
- Information, Interactive Diagnostics, Request Tracing
- Password protected
The content negotiation pipeline will inspect the incoming Accept headers and determine which of the requested media types is the most suitable and format the response accordingly.
Default Response Processors
- JSON - application/json, application/vnd.foo+json
- View - text/html
- XML - application/xml, application/vnd.foo+xml
File extenstion support
- extension-based access “hotwires” negotiation
- Example: /ratpack.json => JSON response
There is no Authentication
What did you say your name Was?
- Nancy has the concept of a User
- No built-in way to authenticate a user
- No inflexible, hard coded, “built in” authentication providers
- Extension points are provided
- Basic, Stateless and Forms mechanisms via Nuget
Forms Authentication
- Install the Nancy.Authentication.Forms package
- Implement an IUserMapper
- Implement routes to handle login and logout
- Configure and enable Forms Authentication