visug session 3/9/2014 - servicestack & nancy
Post on 18-Jul-2015
941 Views
Preview:
TRANSCRIPT
IT IS ABOUT PEOPLE!
ServiceStack & NancyCan they be of service?
#VISUG
IT IS ABOUT PEOPLE!
Overview
IntroServiceStack
The philosophyThe frameworkDemo: A ServiceStack example
NancyThe philosophyThe frameworkDemo: A similar Nancy service
Comparison & ConclusionQuestions
#VISUG
IT IS ABOUT PEOPLE!
Who is this Hannes Lowette guy?
.Net consultant @ AxxesLives in Mol – For you city folk: this is not Limburg
Born in Hasselt – This is Limburg
25 years old – Or 00010000
Father of 1,75 kids
Likes: Duplo, Poker, Absinthe, Whisky & Guitars(amongst other things)
hannes.lowette@axxes.combe.linkedin.com/in/hanneslowette/
#VISUG
IT IS ABOUT PEOPLE!
A history of service frameworks in .NET
ASMXActive Server Method FileHeeft IIS nodigEnkel HTTP (SOAP 1.1 & 1.2)Vanaf .Net 1.1
WSEWeb service extensionsWS-* standaarden in ASMXSOAP en RESTSecurity
#VISUG
IT IS ABOUT PEOPLE!
A history of service frameworks in .NET
WCF (introduced in .Net 3.0)WCF = “Services done right”
Volledig uitbreidbaar en aanpasbaar
CompatibiliteitVeel WS-* standaarden reeds geïmplementeerd
FlexibelTransport (HTTP, TCP, MSMQ, …)
Format (SOAP, REST, JSON, …)
Onafhankelijk van IIS
#VISUG
IT IS ABOUT PEOPLE!
A history of service frameworks in .NET
ADO.Net Data Services (Astoria)AtompubRESTLater Odata
WebAPIRESTDecent content negotiationMVC-like ControllersStill depends on IIS
ServiceStack & Nancy tried to fill the gap
#VISUG
IT IS ABOUT PEOPLE!
SERVICESTACK
Simplicity at Speed.
One framework to power them all
#VISUG
IT IS ABOUT PEOPLE!
What is ServiceStack? – The Service
“One size fits all” service framework:
SOAP, REST & MQ type services
Multi-format: XML, JSON, CSV, JSV, …
Razor view engine
An alternative to WCF, WebAPI and MVC
#VISUG
IT IS ABOUT PEOPLE!
What is ServiceStack? – The Stack
ORMSerializersFiltersLoggingClient FrameworkCachingAuthenticationRedis Client…
#VISUG
IT IS ABOUT PEOPLE!
The philosophy
1 operation = 1 Request DTO (philosophically)
SimplicityPOCO (Code First) approachConvention basedFocus on core logicMinimize configuration
Let the developer think about the logic, not the transport
#VISUG
IT IS ABOUT PEOPLE!
The philosophy (2)
Speed
Every part is written or chosen for speed
Use of conventions to increase performance
Simplify things for added speed
Every part of the stack is important,from the ORM to the serializers
#VISUG
IT IS ABOUT PEOPLE!
Server Architecture
#VISUG
IT IS ABOUT PEOPLE!
Client Architecture
#VISUG
IT IS ABOUT PEOPLE!
Client Architecture (2)
#VISUG
IT IS ABOUT PEOPLE!
Demo time
Remember this?
“Plug & play”
#VISUG
IT IS ABOUT PEOPLE!
NANCY
A lightweight, low-ceremony, framework for building HTTP based services
#VISUG
IT IS ABOUT PEOPLE!
.Net port of Sinatra
#VISUG
IT IS ABOUT PEOPLE!
The Philosophy
The Super-Duper-Happy-Path (SDHP):
It just works
Easily customizable
Low ceremony
Low friction
#VISUG
IT IS ABOUT PEOPLE!
The Framework
100% route-based
Choice of serializers:
Nancy, Newtonsoft, ServiceStack, …
Choice of View Engines:
Razor, Handlebars, Spark, …
Choice of hosting environments:
ASP.NET, OWIN, Self-hosted, Mono, …
#VISUG
IT IS ABOUT PEOPLE!
Nancy app in a tweet
#VISUG
IT IS ABOUT PEOPLE!
Demo time
Think they learned?
#VISUG
IT IS ABOUT PEOPLE!
Url Patterns (1/2)
Literal segment (10000)/some/literal/segments exact match
Capture segment (1000)/{name} catures a portion of the route
Optional capture segment (1000)/{name?}
Optional capture segment with default (1000)/{name?unnamed} what comes after the ? is the default
#VISUG
IT IS ABOUT PEOPLE!
Url Patterns (2/2)
RegEx segment (1000)/(?<age>[\d]{1,2}) named group capture, if needed
Greedy Segment (0)/{name*} matches everything from this / forward
Greedy RegEx Segment (100) /^(?<name>[a-z]{3,10}(?:/{1})(?<action>[a-z]{5,10}))$ Always starts with ^ and ends with $
Multiple Captures Segment (100)/{file}.{extension} (2 captures)/{file}.ext (capture & literals)
#VISUG
IT IS ABOUT PEOPLE!
Action return valuesReturn value Interpreted as …
int HTTP status code
HttpStatusCode (enum) HTTP status code (duh!)
string Response body
Action<Stream> Stream writes the response body
Anything else Content negotiation
#VISUG
IT IS ABOUT PEOPLE!
Route conditions
Func<NancyContext, bool>Post["/login", (ctx) => ctx.Request.Form.remember] = _ => {
return "Handling code when remember is true!";}
Post["/login", (ctx) => !ctx.Request.Form.remember] = _ => {
return "Handling code when remember is false!";}
#VISUG
IT IS ABOUT PEOPLE!
Route segment constraints
Get["/intConstraint/{value:int}"]int, decimal, guid, boolalpha (only alphabetical chars)datetime, datetime(format)min(minimum), max(maximum), range(minimum, maximum) (integer values only)minlength(length), maxlength(length), length(minimum, maximum)Custom …
#VISUG
IT IS ABOUT PEOPLE!
Locating Views
ViewName (from returned type)Tournament Tournament.cshtmlTournamentModel Tournament.cshtml
Locations://Views/Views/ModulePath/ModulePath/ModuleName/Views/ModuleName
#VISUG
IT IS ABOUT PEOPLE!
WRAPPING THINGS UP
Because we’d like to get to the beer…
#VISUG
IT IS ABOUT PEOPLE!
Comparison
ServiceStack Nancy+ Multiple protocols+ Focus on DTO objects+ Focus on speed+ Queue support+ Client packages
- From v.4: €€€- Lots of DTO objects
Components easily interchangeable +Focus on developer happiness +
Does REST extremely well +Different View Engines +
Focus on routes +
Nancy attributes in Data -Route discipline -
#VISUG
IT IS ABOUT PEOPLE!
Conclusion
#VISUG
IT IS ABOUT PEOPLE!
The End … or nearly so
First … Questions
Then … Drinks next door @ De Kaai
#VISUG
top related