owin from spec to application

24
OWIN : From Spec to Application Damian Hickey @randompunter / dhickey.ie dotned, 26 June 2014

Upload: damian-h

Post on 08-Jul-2015

1.564 views

Category:

Software


0 download

DESCRIPTION

Slides from DotNed user group, June 2014

TRANSCRIPT

Page 1: Owin from spec to application

OWIN : From Spec to Application

Damian Hickey

@randompunter / dhickey.ie

dotned, 26 June 2014

Page 2: Owin from spec to application

> whoami

• Not a web or http expert!

Page 3: Owin from spec to application

My Pain

Web APPIIS

WindowsService

SQL Database

WCF

Page 4: Owin from spec to application

Everyone does their own thing

• ServiceStack Selfhost

• Nancy Selfhost

• WebAPI Selfhost

• WCF Selfhost

• OpenRasta Selfhost

• etc

Page 5: Owin from spec to application

The Plan

• Part 1: OWIN• Raison d'être

• Design goals

• The Specification

• Part 2: Implementations• Hosts & Middleware

• Testing

• Samples & Recipes

• Part 3: OWIN in the wild

Page 6: Owin from spec to application

Part 1 – OWIN

Open Web Interface for .NET

Page 7: Owin from spec to application

Prior Art

• System.Web• Complicated lifecycle• Doesn’t look like HTTP• Tied to IIS, in most part• Difficult to test• Doesn’t look like HTTP

• Web Forms (let’s not talk about that)

• MVC rests on same System.Web bits as Web Forms

• Python: Web Server Gateway Interface (WSGI)

• Ruby: Rack

• Java\Clojure: Ring

Page 8: Owin from spec to application

ASP.NET Life Cycle

(Browser)

Page 9: Owin from spec to application
Page 10: Owin from spec to application

What is OWIN?

• A specification, not a technology, created by the community

• Defines a standard, minimal, interface between .NET web servers and web applications

• Decouples server from applications / frameworks

Page 11: Owin from spec to application

Design Goals

• Super simple signature for Applications and Middleware

• Dependency free (library and config)

• Asynchronous and concurrent by design

• Respect HTTP – Requests, Responses, Headers and Streams

• Composable

Page 12: Owin from spec to application

Terminology

• Host

• Middleware

• Web Framework

• Web Application

• Process (aka Sever)

Page 13: Owin from spec to application

IISSystemWeb

Helios

HttpListener

WebListener

Nowin

HTTTP.SYS

SocketsKestrel (libuv)

NGIXApache(FastCGI

FIOS

OWIN (AppFunc)

Application- Nancy- WebAPI- Security- Compression- FileServer- WebSockets- MVC 6- Mapping- Limiting- StatusCodeHandling- ViewEngines- Routing- etc

Page 14: Owin from spec to application

Headers

Request Stream

Body Stream

Headers

Response Stream

Body Stream

OWIN

Page 15: Owin from spec to application

The Core – The Application Function• Aka “AppFunc”

• That’s it!

Page 16: Owin from spec to application

App

Page 17: Owin from spec to application

The Environment Dictionary

• IDictionary<string, object>

• Has a set of well-defined keys and value types

• Stores Request & Response data

• Is mutable

Page 18: Owin from spec to application

The Environment(Browser, owin.org)

Page 19: Owin from spec to application

Middleware

Middleware is a pipeline

Middleware Middleware

Page 20: Owin from spec to application

Middleware

Page 21: Owin from spec to application

Some Rules

• Http pipelining is handled by the server. Do not respond with 100 Continues

• Never close the response body stream

• Always complete the Task

Page 22: Owin from spec to application

Code

(VS)

Page 23: Owin from spec to application

Testing

Page 24: Owin from spec to application

Resources

• owin.org

• katanaproject.codeplex.com

• #owin chat room on jabbr.net

• .NET HTTP Abstractions google group

• github.com/owin