WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of...

26
REST-baserade tjänster med WCF ASP.NET Web API Robert Folkesson Active Solution

Transcript of WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of...

Page 1: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

REST-baserade tjänster med WCF ASP.NET Web APIRobert Folkesson

Active Solution

Page 2: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

WHO AM I?

Page 3: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

REST?• Dissertation by Roy Fielding 2000• “Architectural Styles and the Design

of Network-based Software Architectures”

• ReST = Representational State Transfer

Page 4: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Architectural constraints• Client–server• Stateless• Cacheable• Layered system• Uniform Interface

Page 5: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Scalability

GET http://fabrikam.com/API/User/42

Page 6: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Guiding principles of REST-interfaces

• Identification of resources• Manipulation of resources through

representations of these resources• Self-descriptive messages• Hypermedia as the engine of

application state

Page 7: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

HATEOASHypermedia as the engine of application state

Page 8: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.
Page 9: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Example of hypermedia representation (Netflix)

Page 10: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Richardsons maturity model

Level 0: The swamp of POX

Level 1: Resources

Level 2: HTPP Verbs

Level 3: Hypermedia Controls

Glory of REST

Page 11: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

REST on Microsoft – some history

• WCF pre-3.5: painful…• WCF 3.5: WebHttpBinding. • WCF REST Starter Kit (no longer

supported)• WCF Data Services (OData)• WCF Web API - Preview 1 - 6

Page 12: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

WCF ASP.NET Web API

Page 13: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

http://www.asp.net/web-api• Goal: One HTTP/ REST / Hypermedia API Fx• Integrated in ASP.NET: Best of both world

Page 14: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

WCF to ASP.NET Web APIWCF Web APIASP.NET Web API

Service => Web API controllerOperation => ActionService contract => n/aEndpoint => n/aURI templates => ASP.NET RoutingMessage handlers => SameFormatters => SameOperation handlers => Filters, model binders

Page 15: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

DEMO – FILE NEW

Page 16: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Media types & Media Formatters

HTTP/1.1 200 OK

Content-Length: 95267

Content-Type: image/png

Accept: text/html,application/xhtml+xml,application/xml

Page 17: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Media types & Media Formatters

• Built in support for: – XML– JSON– form-urlencoded data

• Can be extended with custom Media Formatters

Page 18: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

DEMO – MEDIA TYPE FORMATTER

Page 19: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Web API on NuGet• Web API hosted in ASP.NET:

– AspNetWebApi

• Self-hosted Web API: – AspNetWebApi.Selfhost

• HttpClient including XML and JSON formatters: – System.Net.Http.Formatting

• JsonValue for navigating and manipulating JSON:– System.Json Newtonsoft.Json

Page 20: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Node-style Web API?

LiteWebServer server = new LiteWebServer("http://localhost"); server.Get("/Hello", (r) => new HttpResponseMessage() { Content = new StringContent("Hello World!") }); server.Post("/Echo", (r) => new HttpResponseMessage() { Content = new StringContent( r.Content.ReadAsStringAsync().Result) }); server.Open();

http://blogs.msdn.com/b/youssefm/archive/2012/02/24/writing-a-lightweight-web-service-using-webapi-building-blocks.aspx

Page 21: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

DEMO – SELF HOSTING

Page 22: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Web API can be used for all levels

Level 0: The swamp of POX

Level 1: Resources

Level 2: HTPP Verbs

Level 3: Hypermedia Controls

Glory of REST

ASP.

NET

Web

API

Page 23: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

OAuth/Claims based security

http://zamd.net/

Page 24: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Open Source: http://aspnetwebapi.codeplex.com

Page 25: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Some good reading

Page 26: WHO AM I? REST? Dissertation by Roy Fielding 2000 Architectural Styles and the Design of Network-based Software Architectures ReST = Representational.

Thank you!

Robert Folkesson | Active [email protected] | @rfolkes

www.robertfolkesson.se