SlideShare a Scribd company logo
1 of 32
Download to read offline
Granuläres .NET-WebDevelopment
...mit Nancy- & Simple.DataFrameworks
Timothée Bourguignon
MATHEMA Software GmbH
The Menu
• First date with Nancy
– Generalities & Basics
– Mini-HackerNews Demo
• Simple.Data
– Overview
– Further Mini-HackerNews Demo
• Second Date with Nancy
• Further Demos
First Date with Nancy
„Lightweight Web Framework for .NET“
nancyfx.org | #nancyfx
Microframework
• Lean API
• Extensible API
• Simple setup
• “Close to the metal”
What has Nancy to offer?
•
•
•
•
•
•
•

Simplicity & Readability
Modularity
OpenSource
"Close" to HTTP
Very explicit routing
Runs anywhere
„Super Duper Happy Path“
„Hello Nancy“
public class MyModule : NancyModule
{
public MyModule()
{
Get["/"] = _ => "Hello World";
}
}
Route
• Composed of
– Method (HTTP Methods: Get, Post, Put…)
– Pattern
– Action (+parameters & result object)
– Condition (optional)

Get["/voteup/{id}"] = x => {
return View["Voteup", x.id];
};
Pattern
• Literal segments: "/customer"
• Capture segments: "/{id}“
• Capture segments (Optional): "/{id?}“
• Capture segments (Optional/Default): "{name?unnamed}“
• Regex Segments: /(?<id>[d]+)
• Greedy Regex Segments: ^(?<name>[a-z]{3,10}(?:/{1}))$
• Greedy Segments: "/{id*}“
Get["/voteup/{id}"] = x => {
return View["Voteup", x.id];
};
Action
• Behavior invoked by a route

Dynamic
Dictionary

Action

Func<dynamic,
dynamic>

Get["/voteup/{id}"] = x => {
return View["Voteup", x.id];
};

Nancy
.Response
<anything>
→ Content
Negociation
View

...
Nancy.Response
• Nancy.Response implicit casts
– Int32 → HTTP Status Code
– String → body of the response

• Response formatters:
– As File, Image, Json, Xml & Redirect
Serving up Views
• Supported View Engines
– SuperSimpleViewEngine
– Razor, Spark, DotLiquid...
– … any other IViewEngine

• View Engine is selected dynamically, based on
the view's file extension
• Views are also discovered
Get["/products"] = _ => {
return View["products.cshtml"];
};
Model Binding
• Module → View
– Any object Type
– dynamics per default

Get["/products"] = _ =>
{
return View["products",
someModel];
};

• View → Module
– Query string
– Captured parameters
– Body of a request

Foo foo = this.Bind();
var foo = this.Bind<Foo>();
this.BindTo(foo);
Hands on Nancy
HackerNews meet Nancy
Simple.Data
...an O/RM without O, R or M
What is Simple.Data?
• Lightweight way of manipulating data
– Based on .NET 4.0's „dynamic“ keyword
– Interprets method and property names
– Maps them to your underlying data-store
– Prevents SQL Injection
– Inspired by Ruby’s ActiveRecord and DataMappers
– Open Source & runs on Mono
– V1.0 rc3 released in Nov. 2012
PM> Install-package Simple.Data.<TheProvider>
18
Database agnostic

19
Fluid Convention

Co
lu
m
Pa
n
ra
m
et
er
s

an
d
m
Co
m

Ta
bl
e/
Vi
ew

db.album.FindAllByGenreId(3);

20
„Hello Simple.Data“
public void GetCustomers()
{
var conString = "…";
dynamic db =
Database.OpenConnection(conString);
dynamic customer = db.Customers.FindById(1);

}

Console.WriteLine("{0}, {1}!",
customer.FirstName, customer.LastName);
Simple CRUD operations
public void CRUD()
{
db.People.FindAllByName("Bob");
db.People.FindByFirstNameAndLastName("Bob", "X");
db.Users.All().OrderByJoinDateDescending();
db.Users.All().OrderByJoinDate().ThenByNickname();
db.People.Insert(Id: 1, FirstName: "Bob");
db.People.Insert(new Person {Id = 1, Name = "Bob"});
db.People.UpdateById(Id: 1, FirstName: "Robert");
db.People.DeleteById(1);
}
Barely less simple operations
//Paging
db.Users.All().OrderByNickname().Skip(10).Take(10);
//Table joins
db.Customers.FindByCustomerId(1).WithOrders();
//Casting
Artist artist = db.Artists.Get(42);
IList<Artist> artists = db.Artists.All().ToList<Artist>();
Nancy, meet Simple.Data
Simple.Data, meet Nancy
Second date with Nancy
In case the SuperDuperHappyPath is not completely Super,
Duper or Happy yet…
Bootstrapper
•
•
•
•

~DSL on top of the IoC container
Responsible for „putting the puzzle together“
Override and extend
Autoregister your dependencies
public class Home : NancyModule
{
public Home(IMessageService service)
{
//If there is only one implementation
// of ImessageService, TinyIoC will
// resolve it and inject it
}
}
Content Negociation
• Client wishes:
– URI Extension: .json, .xml …
– Header information: „Accept: application/xml“

• Actions output:
– ResponseObject
• Response.AsXml(), Response.AsJson()...

– ContentNegociation
• Default ResponseProcessors: View, Xml, Json...
return Negotiate.WithModel(model)
.WithView("MyView");
Authentication
public class MyBootstrapper : DefaultNancyBootstrapper
{
protected override void InitialiseInternal(TinyIoCContainer container)
{
base.InitialiseInternal(container);
FormsAuthentication.Enable(this,
new FormsAuthenticationConfiguration
{
RedirectUrl = "~/login",
UsernameMapper = container.Resolve<IUsernameMapper>()
});
}}
public class MyModule : NancyModule
{
public MyModule() : base("/secure")
{
this.RequiresAuthentication();
Get["/"] = _ => "Secure!";
}
}
Testing
[Test]
public void Should_redirect_to_login_with_error_details_incorrect()
{
// Given
var bootstrapper = new DefaultNancyBootstrapper();
var browser = new Browser(bootstrapper);
// When
var response = browser.Post("/login/", (with) =>
{
with.HttpRequest();
with.FormValue("Username", "username");
with.FormValue("Password", "wrongpassword");
});
// Then
response.ShouldHaveRedirectedTo(
"/login?error=true&username=username");
}

PM> Install-package Nancy.Testing
Nancy.Diagnostic
• localhost/_nancy
– Information
– Interactive diagnostic

– Request Tracing
– Settings
.NetHackerNews
Nancy Self-Hosted
Wrap-up!
• Simple, readable & flexible frameworks
• Run everywhere
• Nancy
• Simple.Data
– Easy to test
– Customisable
– Great for Webservices

– Powerful
– DB Agnostic
– Compelling

• Excellent for prototypes & small projects
• „Super duper happy path“
Further Reading
• Github
– https://github.com/markrendle/Simple.Data
– https://github.com/NancyFx/Nancy

• GoogleGroups

– Simpledata
– Nancy-web-framework

33
Contacts
• Andreas Håkansson (NancyFx)
– @TheCodeJunkie

• Steven Robbins (NancyFx, TinyIoC)
– @Grumpydev
– http://www.grumpydev.com/

• Mark Rendle (Simple.Data)
– @MarkRendle
– http://blog.markrendle.net/
Ich freue mich auf Eure Fragen!
tim.bourguignon@mathema.de
about.me/timbourguignon

35

More Related Content

What's hot

Evolution of integration and microservices patterns with service mesh
Evolution of integration and microservices patterns with service meshEvolution of integration and microservices patterns with service mesh
Evolution of integration and microservices patterns with service meshChristian Posta
 
Warsaw muleSoft meetup #11 MuleSoft OData
Warsaw muleSoft meetup #11 MuleSoft ODataWarsaw muleSoft meetup #11 MuleSoft OData
Warsaw muleSoft meetup #11 MuleSoft ODataPatryk Bandurski
 
Node.js Blockchain Implementation
Node.js Blockchain ImplementationNode.js Blockchain Implementation
Node.js Blockchain ImplementationGlobalLogic Ukraine
 
JavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EEJavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EERodrigo Cândido da Silva
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackdivyapisces
 
TabTale Architecture Overview
TabTale Architecture OverviewTabTale Architecture Overview
TabTale Architecture OverviewAssaf Gannon
 
The Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsThe Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsDor Kalev
 
Blazor certification training - Dot Net Tricks
Blazor certification training - Dot Net TricksBlazor certification training - Dot Net Tricks
Blazor certification training - Dot Net TricksGaurav Singh
 
autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3Andy Moncsek
 
Building Services with WSO2 Microservices framework for Java and WSO2 AS
Building Services with WSO2 Microservices framework for Java and WSO2 ASBuilding Services with WSO2 Microservices framework for Java and WSO2 AS
Building Services with WSO2 Microservices framework for Java and WSO2 ASKasun Gajasinghe
 
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB
 
Social network with microservices
Social network with microservicesSocial network with microservices
Social network with microservicesViet Tran
 
Ieee S&P 2020 - Software Security: from Research to Industry.
Ieee S&P 2020 - Software Security: from Research to Industry.Ieee S&P 2020 - Software Security: from Research to Industry.
Ieee S&P 2020 - Software Security: from Research to Industry.Minded Security
 
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...Matthew Groves
 
Rapid Application Development with MEAN Stack
Rapid Application Development with MEAN StackRapid Application Development with MEAN Stack
Rapid Application Development with MEAN StackAvinash Kaza
 
Glass fish performance tuning tips from the field
Glass fish performance tuning tips from the fieldGlass fish performance tuning tips from the field
Glass fish performance tuning tips from the fieldPayara
 
CloudStack challenges for China customers
CloudStack challenges for China customersCloudStack challenges for China customers
CloudStack challenges for China customersgavin_lee
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice frameworkFabrice Sznajderman
 

What's hot (20)

Evolution of integration and microservices patterns with service mesh
Evolution of integration and microservices patterns with service meshEvolution of integration and microservices patterns with service mesh
Evolution of integration and microservices patterns with service mesh
 
Warsaw muleSoft meetup #11 MuleSoft OData
Warsaw muleSoft meetup #11 MuleSoft ODataWarsaw muleSoft meetup #11 MuleSoft OData
Warsaw muleSoft meetup #11 MuleSoft OData
 
Node.js Blockchain Implementation
Node.js Blockchain ImplementationNode.js Blockchain Implementation
Node.js Blockchain Implementation
 
JavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EEJavaOne 2016 - Reactive Microservices with Java and Java EE
JavaOne 2016 - Reactive Microservices with Java and Java EE
 
Live Node.JS Training
Live Node.JS TrainingLive Node.JS Training
Live Node.JS Training
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stack
 
TabTale Architecture Overview
TabTale Architecture OverviewTabTale Architecture Overview
TabTale Architecture Overview
 
The Dark Side of Single Page Applications
The Dark Side of Single Page ApplicationsThe Dark Side of Single Page Applications
The Dark Side of Single Page Applications
 
Blazor certification training - Dot Net Tricks
Blazor certification training - Dot Net TricksBlazor certification training - Dot Net Tricks
Blazor certification training - Dot Net Tricks
 
autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3autodiscoverable microservices with vertx3
autodiscoverable microservices with vertx3
 
Building Services with WSO2 Microservices framework for Java and WSO2 AS
Building Services with WSO2 Microservices framework for Java and WSO2 ASBuilding Services with WSO2 Microservices framework for Java and WSO2 AS
Building Services with WSO2 Microservices framework for Java and WSO2 AS
 
Using NodeJS for Real-Time Web
Using NodeJS for Real-Time WebUsing NodeJS for Real-Time Web
Using NodeJS for Real-Time Web
 
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN StackMongoDB Days Silicon Valley: Building Applications with the MEAN Stack
MongoDB Days Silicon Valley: Building Applications with the MEAN Stack
 
Social network with microservices
Social network with microservicesSocial network with microservices
Social network with microservices
 
Ieee S&P 2020 - Software Security: from Research to Industry.
Ieee S&P 2020 - Software Security: from Research to Industry.Ieee S&P 2020 - Software Security: from Research to Industry.
Ieee S&P 2020 - Software Security: from Research to Industry.
 
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
 
Rapid Application Development with MEAN Stack
Rapid Application Development with MEAN StackRapid Application Development with MEAN Stack
Rapid Application Development with MEAN Stack
 
Glass fish performance tuning tips from the field
Glass fish performance tuning tips from the fieldGlass fish performance tuning tips from the field
Glass fish performance tuning tips from the field
 
CloudStack challenges for China customers
CloudStack challenges for China customersCloudStack challenges for China customers
CloudStack challenges for China customers
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice framework
 

Viewers also liked

AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...Bojan Veljanovski
 
Scala for Java Developers - Intro
Scala for Java Developers - IntroScala for Java Developers - Intro
Scala for Java Developers - IntroDavid Copeland
 
Microservices com ASP.NET 5
Microservices com ASP.NET 5Microservices com ASP.NET 5
Microservices com ASP.NET 5Waldyr Felix
 
Designing and building a micro-services architecture. Stairway to heaven or a...
Designing and building a micro-services architecture. Stairway to heaven or a...Designing and building a micro-services architecture. Stairway to heaven or a...
Designing and building a micro-services architecture. Stairway to heaven or a...Sander Hoogendoorn
 
Building .NET Microservices
Building .NET MicroservicesBuilding .NET Microservices
Building .NET MicroservicesVMware Tanzu
 
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20....Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...Javier García Magna
 
Developing applications with a microservice architecture (svcc)
Developing applications with a microservice architecture (svcc)Developing applications with a microservice architecture (svcc)
Developing applications with a microservice architecture (svcc)Chris Richardson
 
Architecting Microservices in .Net
Architecting Microservices in .NetArchitecting Microservices in .Net
Architecting Microservices in .NetRichard Banks
 
Micro Service Architecture
Micro Service ArchitectureMicro Service Architecture
Micro Service ArchitectureEduards Sizovs
 
MicroService Architecture
MicroService ArchitectureMicroService Architecture
MicroService ArchitectureFred George
 
Microservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Web Applications using AWS Lambda and moreMicroservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Web Applications using AWS Lambda and moreMitoc Group
 

Viewers also liked (12)

AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
 
Scala for Java Developers - Intro
Scala for Java Developers - IntroScala for Java Developers - Intro
Scala for Java Developers - Intro
 
Microservices com ASP.NET 5
Microservices com ASP.NET 5Microservices com ASP.NET 5
Microservices com ASP.NET 5
 
Designing and building a micro-services architecture. Stairway to heaven or a...
Designing and building a micro-services architecture. Stairway to heaven or a...Designing and building a micro-services architecture. Stairway to heaven or a...
Designing and building a micro-services architecture. Stairway to heaven or a...
 
Building .NET Microservices
Building .NET MicroservicesBuilding .NET Microservices
Building .NET Microservices
 
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20....Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
 
Developing applications with a microservice architecture (svcc)
Developing applications with a microservice architecture (svcc)Developing applications with a microservice architecture (svcc)
Developing applications with a microservice architecture (svcc)
 
From SOA to MSA
From SOA to MSAFrom SOA to MSA
From SOA to MSA
 
Architecting Microservices in .Net
Architecting Microservices in .NetArchitecting Microservices in .Net
Architecting Microservices in .Net
 
Micro Service Architecture
Micro Service ArchitectureMicro Service Architecture
Micro Service Architecture
 
MicroService Architecture
MicroService ArchitectureMicroService Architecture
MicroService Architecture
 
Microservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Web Applications using AWS Lambda and moreMicroservices Architecture for Web Applications using AWS Lambda and more
Microservices Architecture for Web Applications using AWS Lambda and more
 

Similar to Introduction to the Nancy Framework

My way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionMy way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionChristian Panadero
 
Webinar: Architecting Secure and Compliant Applications with MongoDB
Webinar: Architecting Secure and Compliant Applications with MongoDBWebinar: Architecting Secure and Compliant Applications with MongoDB
Webinar: Architecting Secure and Compliant Applications with MongoDBMongoDB
 
Architecting Secure and Compliant Applications with MongoDB
Architecting Secure and Compliant Applications with MongoDB        Architecting Secure and Compliant Applications with MongoDB
Architecting Secure and Compliant Applications with MongoDB MongoDB
 
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Codemotion
 
Nancy & Simple.Data from ProgNet 11
Nancy & Simple.Data from ProgNet 11Nancy & Simple.Data from ProgNet 11
Nancy & Simple.Data from ProgNet 11Mark Rendle
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiInfluxData
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
My way to clean android (EN) - Android day salamanca edition
My way to clean android (EN) - Android day salamanca editionMy way to clean android (EN) - Android day salamanca edition
My way to clean android (EN) - Android day salamanca editionChristian Panadero
 
RedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedis Labs
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBMongoDB
 
Nancy - A Lightweight .NET Web Framework
Nancy - A Lightweight .NET Web FrameworkNancy - A Lightweight .NET Web Framework
Nancy - A Lightweight .NET Web FrameworkChristian Horsdal
 
20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnddo_aki
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsRichard Rodger
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015NoSQLmatters
 
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM BluemixOffline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM BluemixIBM
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSuzquiano
 

Similar to Introduction to the Nancy Framework (20)

My way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionMy way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca edition
 
Webinar: Architecting Secure and Compliant Applications with MongoDB
Webinar: Architecting Secure and Compliant Applications with MongoDBWebinar: Architecting Secure and Compliant Applications with MongoDB
Webinar: Architecting Secure and Compliant Applications with MongoDB
 
Architecting Secure and Compliant Applications with MongoDB
Architecting Secure and Compliant Applications with MongoDB        Architecting Secure and Compliant Applications with MongoDB
Architecting Secure and Compliant Applications with MongoDB
 
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
 
Nancy & Simple.Data from ProgNet 11
Nancy & Simple.Data from ProgNet 11Nancy & Simple.Data from ProgNet 11
Nancy & Simple.Data from ProgNet 11
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
My way to clean android (EN) - Android day salamanca edition
My way to clean android (EN) - Android day salamanca editionMy way to clean android (EN) - Android day salamanca edition
My way to clean android (EN) - Android day salamanca edition
 
Node azure
Node azureNode azure
Node azure
 
RedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis code
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
Nancy - A Lightweight .NET Web Framework
Nancy - A Lightweight .NET Web FrameworkNancy - A Lightweight .NET Web Framework
Nancy - A Lightweight .NET Web Framework
 
20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnd
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
 
20120816 nodejsdublin
20120816 nodejsdublin20120816 nodejsdublin
20120816 nodejsdublin
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
 
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
Michael Hackstein - NoSQL meets Microservices - NoSQL matters Dublin 2015
 
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM BluemixOffline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
Offline-First Mobile Web Apps with PouchDB, IBM Cloudant, and IBM Bluemix
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMS
 

Recently uploaded

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Introduction to the Nancy Framework

  • 1. Granuläres .NET-WebDevelopment ...mit Nancy- & Simple.DataFrameworks Timothée Bourguignon MATHEMA Software GmbH
  • 2. The Menu • First date with Nancy – Generalities & Basics – Mini-HackerNews Demo • Simple.Data – Overview – Further Mini-HackerNews Demo • Second Date with Nancy • Further Demos
  • 3. First Date with Nancy „Lightweight Web Framework for .NET“ nancyfx.org | #nancyfx
  • 4. Microframework • Lean API • Extensible API • Simple setup • “Close to the metal”
  • 5. What has Nancy to offer? • • • • • • • Simplicity & Readability Modularity OpenSource "Close" to HTTP Very explicit routing Runs anywhere „Super Duper Happy Path“
  • 6. „Hello Nancy“ public class MyModule : NancyModule { public MyModule() { Get["/"] = _ => "Hello World"; } }
  • 7. Route • Composed of – Method (HTTP Methods: Get, Post, Put…) – Pattern – Action (+parameters & result object) – Condition (optional) Get["/voteup/{id}"] = x => { return View["Voteup", x.id]; };
  • 8. Pattern • Literal segments: "/customer" • Capture segments: "/{id}“ • Capture segments (Optional): "/{id?}“ • Capture segments (Optional/Default): "{name?unnamed}“ • Regex Segments: /(?<id>[d]+) • Greedy Regex Segments: ^(?<name>[a-z]{3,10}(?:/{1}))$ • Greedy Segments: "/{id*}“ Get["/voteup/{id}"] = x => { return View["Voteup", x.id]; };
  • 9. Action • Behavior invoked by a route Dynamic Dictionary Action Func<dynamic, dynamic> Get["/voteup/{id}"] = x => { return View["Voteup", x.id]; }; Nancy .Response <anything> → Content Negociation View ...
  • 10. Nancy.Response • Nancy.Response implicit casts – Int32 → HTTP Status Code – String → body of the response • Response formatters: – As File, Image, Json, Xml & Redirect
  • 11. Serving up Views • Supported View Engines – SuperSimpleViewEngine – Razor, Spark, DotLiquid... – … any other IViewEngine • View Engine is selected dynamically, based on the view's file extension • Views are also discovered Get["/products"] = _ => { return View["products.cshtml"]; };
  • 12. Model Binding • Module → View – Any object Type – dynamics per default Get["/products"] = _ => { return View["products", someModel]; }; • View → Module – Query string – Captured parameters – Body of a request Foo foo = this.Bind(); var foo = this.Bind<Foo>(); this.BindTo(foo);
  • 15. What is Simple.Data? • Lightweight way of manipulating data – Based on .NET 4.0's „dynamic“ keyword – Interprets method and property names – Maps them to your underlying data-store – Prevents SQL Injection – Inspired by Ruby’s ActiveRecord and DataMappers – Open Source & runs on Mono – V1.0 rc3 released in Nov. 2012 PM> Install-package Simple.Data.<TheProvider> 18
  • 18. „Hello Simple.Data“ public void GetCustomers() { var conString = "…"; dynamic db = Database.OpenConnection(conString); dynamic customer = db.Customers.FindById(1); } Console.WriteLine("{0}, {1}!", customer.FirstName, customer.LastName);
  • 19. Simple CRUD operations public void CRUD() { db.People.FindAllByName("Bob"); db.People.FindByFirstNameAndLastName("Bob", "X"); db.Users.All().OrderByJoinDateDescending(); db.Users.All().OrderByJoinDate().ThenByNickname(); db.People.Insert(Id: 1, FirstName: "Bob"); db.People.Insert(new Person {Id = 1, Name = "Bob"}); db.People.UpdateById(Id: 1, FirstName: "Robert"); db.People.DeleteById(1); }
  • 20. Barely less simple operations //Paging db.Users.All().OrderByNickname().Skip(10).Take(10); //Table joins db.Customers.FindByCustomerId(1).WithOrders(); //Casting Artist artist = db.Artists.Get(42); IList<Artist> artists = db.Artists.All().ToList<Artist>();
  • 22. Second date with Nancy In case the SuperDuperHappyPath is not completely Super, Duper or Happy yet…
  • 23. Bootstrapper • • • • ~DSL on top of the IoC container Responsible for „putting the puzzle together“ Override and extend Autoregister your dependencies public class Home : NancyModule { public Home(IMessageService service) { //If there is only one implementation // of ImessageService, TinyIoC will // resolve it and inject it } }
  • 24. Content Negociation • Client wishes: – URI Extension: .json, .xml … – Header information: „Accept: application/xml“ • Actions output: – ResponseObject • Response.AsXml(), Response.AsJson()... – ContentNegociation • Default ResponseProcessors: View, Xml, Json... return Negotiate.WithModel(model) .WithView("MyView");
  • 25. Authentication public class MyBootstrapper : DefaultNancyBootstrapper { protected override void InitialiseInternal(TinyIoCContainer container) { base.InitialiseInternal(container); FormsAuthentication.Enable(this, new FormsAuthenticationConfiguration { RedirectUrl = "~/login", UsernameMapper = container.Resolve<IUsernameMapper>() }); }} public class MyModule : NancyModule { public MyModule() : base("/secure") { this.RequiresAuthentication(); Get["/"] = _ => "Secure!"; } }
  • 26. Testing [Test] public void Should_redirect_to_login_with_error_details_incorrect() { // Given var bootstrapper = new DefaultNancyBootstrapper(); var browser = new Browser(bootstrapper); // When var response = browser.Post("/login/", (with) => { with.HttpRequest(); with.FormValue("Username", "username"); with.FormValue("Password", "wrongpassword"); }); // Then response.ShouldHaveRedirectedTo( "/login?error=true&username=username"); } PM> Install-package Nancy.Testing
  • 27. Nancy.Diagnostic • localhost/_nancy – Information – Interactive diagnostic – Request Tracing – Settings
  • 29. Wrap-up! • Simple, readable & flexible frameworks • Run everywhere • Nancy • Simple.Data – Easy to test – Customisable – Great for Webservices – Powerful – DB Agnostic – Compelling • Excellent for prototypes & small projects • „Super duper happy path“
  • 30. Further Reading • Github – https://github.com/markrendle/Simple.Data – https://github.com/NancyFx/Nancy • GoogleGroups – Simpledata – Nancy-web-framework 33
  • 31. Contacts • Andreas Håkansson (NancyFx) – @TheCodeJunkie • Steven Robbins (NancyFx, TinyIoC) – @Grumpydev – http://www.grumpydev.com/ • Mark Rendle (Simple.Data) – @MarkRendle – http://blog.markrendle.net/
  • 32. Ich freue mich auf Eure Fragen! tim.bourguignon@mathema.de about.me/timbourguignon 35