SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler 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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 
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
 
NoSQL meets Microservices
NoSQL meets MicroservicesNoSQL meets Microservices
NoSQL meets Microservices
 
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
 

Último

Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 

Último (20)

Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 

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