Visug session 3/9/2014 - ServiceStack & Nancy

31
IT IS ABOUT PEOPLE! ServiceStack & Nancy Can they be of service? #VISUG

Transcript of Visug session 3/9/2014 - ServiceStack & Nancy

Page 1: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

ServiceStack & NancyCan they be of service?

#VISUG

Page 2: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Overview

IntroServiceStack

The philosophyThe frameworkDemo: A ServiceStack example

NancyThe philosophyThe frameworkDemo: A similar Nancy service

Comparison & ConclusionQuestions

#VISUG

Page 3: Visug session 3/9/2014 - ServiceStack & Nancy

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)

[email protected]/in/hanneslowette/

#VISUG

Page 4: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 5: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 6: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 7: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

SERVICESTACK

Simplicity at Speed.

One framework to power them all

#VISUG

Page 8: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 9: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

What is ServiceStack? – The Stack

ORMSerializersFiltersLoggingClient FrameworkCachingAuthenticationRedis Client…

#VISUG

Page 10: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 11: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 12: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Server Architecture

#VISUG

Page 13: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Client Architecture

#VISUG

Page 14: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Client Architecture (2)

#VISUG

Page 15: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Demo time

Remember this?

“Plug & play”

#VISUG

Page 16: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

NANCY

A lightweight, low-ceremony, framework for building HTTP based services

#VISUG

Page 17: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

.Net port of Sinatra

#VISUG

Page 18: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

The Philosophy

The Super-Duper-Happy-Path (SDHP):

It just works

Easily customizable

Low ceremony

Low friction

#VISUG

Page 19: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 20: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Nancy app in a tweet

#VISUG

Page 21: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Demo time

Think they learned?

#VISUG

Page 22: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 23: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 24: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 25: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 26: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 27: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Locating Views

ViewName (from returned type)Tournament Tournament.cshtmlTournamentModel Tournament.cshtml

Locations://Views/Views/ModulePath/ModulePath/ModuleName/Views/ModuleName

#VISUG

Page 28: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

WRAPPING THINGS UP

Because we’d like to get to the beer…

#VISUG

Page 29: Visug session 3/9/2014 - ServiceStack & Nancy

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

Page 30: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

Conclusion

#VISUG

Page 31: Visug session 3/9/2014 - ServiceStack & Nancy

IT IS ABOUT PEOPLE!

The End … or nearly so

First … Questions

Then … Drinks next door @ De Kaai

#VISUG