1 of 99

Slide Notes

DownloadGo Live

NancyFX

Published on Nov 19, 2015

Introductory presentation about NancyFX. ASP.Net's super-duper-happy framework.

PRESENTATION OUTLINE

Untitled Slide

Untitled Slide

Untitled Slide

Untitled Slide

Andreas håkansson

a.k.a. @TheCodeJunkie

Inspired by a framework called Sinatra

(note the word inspired)

Who's This Nancy?

These boots are made for Walkin'

#1 Song in 1966
Photo by Felix_Nine

Untitled Slide

Hardest problem in programming is naming things

Why Nancy?

It's Easier and More Funner

Photo by steffenz

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)

Easier Testing

Out of the Box

TinyIOC
(or use your favorite IOC)

Automatic Dependency Resolution

Ultra light Action Declarations

GET, HEAD, PUT, POST, DELETE, OPTIONS and PATCH requests

View Engines

  • Razor
  • Spark
  • Super Simple View Engine
  • dotLiquid
  • Markdown and many more...
Photo by Alan Cleaver

Powerful request path matching

includes advanced parameter capabilities

Content NEgotiation

JSON, XML, HTML

OPen Source

Bonus: You can actually understand the code
Photo by kugel

community

182 Contributors and Counting

super-duper-happy path

The Ethos of Nancy
Photo by play4smee

Minimal Configuration Required

Easily Customized

Photo by dok1

LoW Ceremony

Photo by moedermens

Low Friction

Exploring Nancy Modules

Modules are the LynchPin

of any Nancy Application

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
Photo by ecstaticist

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

Photo by angeloangelo

Module Paths

Untitled Slide

Routes

METHOD + PATTERN + ACTION + CONDITION
Photo by tommaync

DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH

Photo by GirlieMac

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

actions

parameters is a DynamicDictionary

Condition

Optional

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.

Untitled Slide

Untitled Slide

Views

Rendering a View

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
Photo by marten vaher

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
Photo by atomicshark

Not good Enough for You?

Define your own

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

Untitled Slide

Untitled Slide

TEsting

Is this Thing Working?
Photo by practicalowl

Untitled Slide

Untitled Slide

Untitled Slide

Untitled Slide

Untitled Slide

TL;DR: stick stuff in /Content .. done.

Managing Static Content
Photo by AdrienneMay

Untitled Slide

Untitled Slide

Untitled Slide

Diagnostics

Diagnostics

  • Built-in to the main assembly
  • http://
    /_Nancy/
  • Fast, extensible and cross-browser compliant.
  • Information, Interactive Diagnostics, Request Tracing
  • Password protected
Photo by deqalb

Untitled Slide

Untitled Slide

Content Negotiation

Photo by salendron

Untitled Slide

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

Untitled Slide

File extenstion support

  • extension-based access “hotwires” negotiation
  • Example: /ratpack.json => JSON response

Authentication

Photo by DaveCrosby

There is no Authentication

Short Answer
Photo by bark

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
Photo by totumweb

Untitled Slide

Untitled Slide

Roll Your Own

An Example License Extension
Photo by Ravages

Untitled Slide

Untitled Slide

Untitled Slide

Untitled Slide

Forms Authentication

  • Install the Nancy.Authentication.Forms package
  • Implement an IUserMapper
  • Implement routes to handle login and logout
  • Configure and enable Forms Authentication
Photo by clickykbd

Untitled Slide

Untitled Slide

Untitled Slide

Why Nancy?

Photo by Essl

It's LIghtWeight

Photo by djwtwo

But it's No Lightweight

Sensible Conventions

Photo by zedworks

Pay as you Go

Extensible

Great Community

Photo by slworking2

Untitled Slide

Mike-Ward.Net

@mikeward_aa

Photo by JD Hancock