rest assured

38
Yaniv Rodenski Senior Consultant, Sela Group http:// blogs.microsoft.co.il/blogs/roadan Twitter: @YRodenski REST Assured

Upload: yaniv-rodenski

Post on 10-May-2015

1.691 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Rest assured

Yaniv Rodenski Senior Consultant, Sela Group

http://blogs.microsoft.co.il/blogs/roadanTwitter: @YRodenski

RESTAssured

Page 2: Rest assured

A brief history of The Web API

Fab 2012

October 2010

March 2012

6 Preview Versions

WCF Web API on Code Plex

ASP.NET Web API (Beta)

ASP.NET is Open Source

Page 3: Rest assured
Page 4: Rest assured

State of the web

• Today the web faces new challenges:– Internet scale applications

– Cloud operating systems

Page 5: Rest assured

State of the web

• Today the web faces new challenges:– Even more complex integrations

Page 6: Rest assured

State of the web

• Today the web faces new challenges:– Broader reach of clients

Page 7: Rest assured

• Basic terminology• REST via the ASP.NET Web API

– Richardson maturity model– Hypermedia Patterns– Media types

• Caching

Agenda

Page 8: Rest assured

• Promise to add “object access”-like semantics to the web– Operation centric– Uses a large message format

• Extensible– Over the years a large amount of extending standards were

created (AKA WS-*)– By extension, adds stateful semantics over the web

• Promotes the use of the proxy pattern• Not web natural• Supported by major development environments

SOAP

Page 9: Rest assured

• Request

• Response

SOAP Service calls

Page 10: Rest assured

• Promise to transfer hypertext• The primal and most native protocol of the

web• Stateless• Supported by almost any device on the face of

the earth

HTTP

Page 11: Rest assured

• Request

• Response

HTTP Service calls

Page 12: Rest assured

• SOA is an architectural approach for distributed systems

• SOA defines four tenets focusing on service autonomy and boundaries

• SOA is a fully mature architecture with well-known patterns and solutions for complex communication and integration scenarios

SOA

Page 13: Rest assured

• The term Representational State Transfer (REST) was coined by Roy Fielding in his Ph.D. thesis in 2000

• An architectural style that embraces HTTP and the World Wide Web

• Web friendly

REST

Page 14: Rest assured

• Leonard Richardson’s maturity model describes four levels of service maturity

Hypermedia

Http

Resources

Richardson maturity model

Page 15: Rest assured

• Level zero services do not use HTTP as an application protocol.

• Use HTTP as a transport for other remote interaction mechanism

Hypermedia

Http

Resources

RMM – Level zero services

SOAP

Page 16: Rest assured

• Level one services acknowledge resources• Resources are accessed via a unique address (formatted as a

Universal Resource Identifier)• When accessed, a resource returns a representation

http://myfooty.com/players/henriquehttp://myfooty.com/players/neymar

Hypermedia

Http

Resources

RMM – Level one services

Page 17: Rest assured

Level one service

Page 18: Rest assured

• In his famous 2001 bath-tub talk Don Box drew the line between web pages and web services by defining their consuming life forms:

Carbon basedWeb Pages

Silicon basedWeb Services

Web neutrality

Page 19: Rest assured

• Level two services use HTTP mechanisms properly:– Verbs– Status codes– Headers

RMM – Level two services

Hypermedia

Http

Resources

Page 20: Rest assured

• HTTP defines different methods (sometimes called verbs) to indicate a desired action to be performed on a resource

• These verbs define a common terminology that is accepted by users, developers and the infrastructure of the World Wide Web

HTTP verbs

Page 21: Rest assured

Using HTTP verbs for CRUD

Page 22: Rest assured

• In addition to a response message, HTTP uses status codes to communicate to the clients the resultant status of the operation

• The first digit of the status code specifies one of five classes of response:– 1xx Informational– 2xx Success – 3xx Redirection– 4xx Client Error– 5xx Server Error

HTTP status codes

Page 23: Rest assured

• HTTP uses headers to transfer metadata regarding the message’s content and transport

• HTTP headers are one of HTTP’s main extensibility points

HTTP headers

Page 24: Rest assured

Level Two Service

Page 25: Rest assured

• Level one and two services deal with resources which represent entities

• Level three services introduce flow management via hypermedia controls (For example: links)

RMM – Level three services

Hypermedia

Http

Resources

Page 26: Rest assured

• Hypermedia is used as a logical extension of the term hypertext in which graphics, audio, video, plain text and hyperlinks intertwine to create a generally non-linear medium of information.

http://en.wikipedia.org/wiki/Hypermedia

RMM – Level three services

Hypermedia

Http

Resources

Page 27: Rest assured

Hypermedia Application

Page 28: Rest assured

Hypermedia Patterns

• Hypermedia can be used to express different behaviors in an application:– Control flow management (State machine)– Discoverability and versioning– Properties management– Aspect management– Paging

Page 29: Rest assured

OData paging

Page 30: Rest assured

• HTTP media types are used to describe the format of the message body

• In REST media types are used describe representations, hypermedia controls, and processing rules

• By creating a media type we can define the application’s domain

Media types (MIME)

Page 31: Rest assured

Using Media Formatters

Page 32: Rest assured

• HTTP caches can store copies of the responses along the request response path to reduce network traffic

• HTTP caches reduces call latency• Caches are a main factor for scalability on the

web

Cache the REST

Page 33: Rest assured

• Browser CacheStores representations locally on the computer’s hard drive

• Proxy Cache Corporates and ISPs provide shared proxies providing shared cache on their network

• Gateway (Reverse Proxy) Cache Stores representations on behalf of the server. Content Delivery Networks (CDNs) use gateway cache distributed around the web

Types of Cache

Page 34: Rest assured

• HTTP headers can be used to control cache behaviors

• HTTP provides method the avoid staleness of cached data – Expiration– Validation

Controlling Cache

Page 35: Rest assured

Controlling Cache Behavior

Page 36: Rest assured

• HTTP is a powerful application level protocol• Built to serve the worlds largest information

system• REST provides an architecture that enables

better use of the inherent scaling capabilities of the web

• Hypermedia enables us to scale and grow our application

Summary

Page 37: Rest assured
Page 38: Rest assured

Roy Fieldinghttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

Architectural Styles and the Design of Network-based Software Architectures http://www.w3.org/Protocols/

ASP.NET Web APIshttp://www.asp.net/web-api/

HTTP/1.1 Specifications

http://bit.ly/roadan (best viewed from multiple ip addresses)

My Blog

http://restinpractice.com/default.aspx REST in practice (Book)

Ido Flatowhttp://scc.sela.co.il/SCC/Pages/ShowLecture/ShowLecture.aspx?lectureId=642

Debugging the web with Fiddler