Resource Oriented Architectures
-
Upload
gabriele-lana -
Category
Documents
-
view
1.728 -
download
0
description
Transcript of Resource Oriented Architectures
what isREST?
a Protocolan Architecture
a Softwarea Standard
a fancy name for Web Servicesa Buzzword
REST is not
RepresentationalStateTransfer
Roy T. Fielding“Architectural Styles and the Design of Network-based Software Architectures”
Ph.D dissertation, 2000
a Software Architecture Stylea set of Constraints on Component
Interaction that, when obeyed, cause the resulting Architecture to have
certain properties
Roy T. Fielding http://roy.gbiv.com/untangled/2008/on-software-architecture
REST is
?
“Roy Fielding will officially disown most of the RESTful authors and software packages
available. Nobody will care, or worse, somebody looking to make a name for themselves will proclaim that “Roy doesn't really understand
REST”, and they'll be right: Roy doesn't understand what they consider to be REST”
http://dotnet.dzone.com/articles/ted-neward-2009-predictions-20
prediction for 2009
“... the motivation for developing REST was to create an architectural model for how the Web
should work, such that it could serve as the guiding framework for the Web protocol
standards”
http://www.ics.uci.edu/~fielding/pubs/dissertation/evaluation.htm
why?
REST vsSOA vsSOAP vsRPC vsWS-* vs
...
no Silver Bullets
but sometimesREST is better :-)
HTTPOOP
RDB
MS
web applicationsInformation Flow
HTTPOOP
RDB
MSHTTP
HTTP is REST
HTTPOOP
RDB
MS
Impedance Mismatch
HTTPOOP
RDB
MS
AccidentalComplexity
HTTPOOP
RDB
MSHTTP
OOP
RDB
MS
EssentialComplexity
RPC
RPC OOP
RDB
MS
HTTP
HTTPRDB
MSROA
Resource Oriented Architectures
HTTP ROA DATA
maybe not today, but Yes, we Can
REST by Example(Chess)
how to Design aRESTful service
Step by Step
Leonard Richardson & Sam Ruby “RESTful Web Services”, O’Reilly 2007
1. every Resource must be Identified
BoardGame
Position
Move
FileRankPlayer
Square
Knight
Queen
Rook
Pawn Bishop
every Concept in your Domain can
be a Resource
2. design the URIs (Ubiquitous Language)
/position/wqd3,wkd1,bqd7,bkd8
/position/wqd3,wkd1,bqe6,bkf8/d3-d8
/move/wqd3,wkd1,bkf8-wqd8,wkd1,bkf8
/position/initial
/board/4815162342
/position/wqd3,wkd1,bqe6,bkf8
/position/wqd8,wkd1,bqe6,bkf8
move = d3-d8
/player/50298
3. for each Resourceexpose a subset of
the Uniform Interface
GET (Read)POST (Create)PUT (Update)
DELETE (Delete)
Uniform Interface
GET /player/50298 HTTP/1.1
Retrieve informations on identified Resource
Idempotent, should not changethe Resource State
POST /position/wqd3,wkd1,bke8 HTTP/1.1\nmove = d3-d8
POST to let Resources process informations
HTTP/1.1 302 FoundLocation: /position/wqd8,wkd1,bke8
POST /game HTTP/1.1\nwhite = /player/50298 &black = /player/39650
POST to Createnew Resources
HTTP/1.1 201 CreatedLocation: /game/42
PUT /board/4815162342 HTTP/1.1\nposition = /position/wqd3,wkd2,bke8
PUT to UpdateResource Informations
HTTP/1.1 205 Reset Content
PUT /position/wqd3,wkd1,bke8 HTTP/1.1\nposition = /position/wqd3,wkd2,bke8
a Method can benot supported by a Resource
but should not be ignored
HTTP/1.1 405 Method Not Allowed
DELETE /board/4815162342 HTTP/1.1
DELETE tologically Remove
Resources
HTTP/1.1 204 No Content
4. for each Resourcedesign Representations
from and to Client
GET /position/wqd3,wkd2,bke8 HTTP/1.1Accept: text/plain
client/server Content Negotiation(MIME properties)
HTTP/1.1 200 OKContent-Type: text/plain;format=fen\n3k4/8/3q4/8/8/8/8/5K2
GET /position/wqd3,wkd2,bke8 HTTP/1.1Accept: image/png;q=0.8, text/plain;q=0.2
HTTP/1.1 200 OKContent-Type: image/png\nPNG...
client/server Content Negotiation(Preferences)
GET /position/wqd3,wkd2,bke8.png HTTP/1.1Accept: image/png
HTTP/1.1 200 OKContent-Type: image/png\nPNG...
client Explicit Request ofContent-Type
GET /position/wqd3,wkd2,bke8.gif HTTP/1.1Accept: image/gif
HTTP/1.1 406 Not Acceptable
or more friendlyHTTP/1.1 300 Multiple ChoicesContent-Type: application/xml \n<choices><content type=”image/png” uri=”...”>
GET /game/42 HTTP/1.1Accept: application/vnd.dharma.chess
<game> <player role=”white”>/player/1001</player> <player role=”black”>/player/1002</player> <moves> <position>/position/initial</position> </moves></game>
custom Content-Type
wait...what about
plain oldWeb Applications?
GET /game/42 HTTP/1.1Accept: application/xhtml+xml
<html> ... <a rel=”owner” href=”/player/1001”>...</a> ... <ul class=”moves”> <li><image src=”/position/initial.png”/></li> </ul></html>
Semantic Web is not a dream
Tim Berners-Leeon Linked Data
“... almost 20 years ago I wanted to reframe the way we use
informations ... I invented the Word Wide Web ... now is time
for a new reframing...”
Tim Berners-Lee @ http://linkeddata.org
expected behavior of the web
1. Use URIs as names for things2. Use HTTP URIs so that people
can look up those names3. When someone looks up a URI,
provide useful information4. Include links to other URIs, so
that they can discover more things
POST /game/42 HTTP/1.1Content-Type: application/vnd.dharma.chess
Authorization: Basic dXN1cm5hbWU6cG...\n<game> <player>...</player> <moves> <position>/position/initial</position>
<position color=”white”> /position/wra1,wna2,...,wpd4,... </position> </moves></game>
... from and to the Client
5. designtypical flowsanderrorconditions
POST /game/42 HTTP/1.1Content-Type: application/vnd.dharma.chessAuthorization: Basic dXN1...\n<game> <player>...</player> <moves> <position>/position/initial</position>
<position color=”white”> /position/wra1,wna2,...,wpd4,... </position> </moves></game>
white Player make first move
HTTP/1.1 201 CreatedLocation: /game/42/position/2
Response to the white Player
GET /game/42/position/2
HTTP/1.1 301 Moved PermanentlyLocation: /position/wra1,wna2,...,wpd4,...
GET /game/42 HTTP/1.1Authorization: Basic dXN1...\n<game> <player>...</player> <moves>...</player></game>
GET /game/42 HTTP/1.1Authorization: Basic aYR5...\n<game> <player>...</player> <moves>...</player></game>
both Players must GETthe game Representation
POST /game/42 HTTP/1.1Content-Type: application/vnd.dharma.chessAuthorization: Basic aYR5...\n<game> <player>...</player> <moves> <position>/position/initial</position> <position>/position/wra1,wna2,...,wpd4,...</position>
<position color=”black”> /position/wra1,wna2,...,bpd5,... </position> </moves></game>
black Player can make next move
POST /game/42 HTTP/1.1Content-Type: application/vnd.dharma.chessAuthorization: Basic aYR5...\n...
what if black Player try to resend?
HTTP/1.1 409 Conflict
the game Representation isout of date
POST /game/42 HTTP/1.1Content-Type: application/vnd.dharma.chessAuthorization: Basic aYR5...\n...
what if black Player try to move again?
HTTP/1.1 403 Forbidden
the black Player should waitfor the white Player to move
Business Rules could be easilyexpressed through the Resource's
Behavior
POST /position/wqd3,wkd1,bke8 HTTP/1.1\nmove = d3-e8
what if we try to make a wrong move?
HTTP/1.1 404 Not Found
wait...what about
complex UserInterfaces?
what about Gmail
HTTP
?
JS
JS
what about Gmail
what about Gmail
FAQ: cool URIsare RESTful?
OpenSocial/people/{guid}/@all
Collection of all people connected to user {guid}http://www.opensocial.org/Technical-Resources/opensocial-spec-v081/restful-protocol.html
FAQ: REST isstateless?
Statelessness says thatall possible states of the server
are also Resources(Resource State)
FAQ: REST isstateless?
Statelessness says thateach message contains
all the informations necessaryto understand the Request
(Application State)
SERVER
R1
R2
R3R4
CLIENT
Application
State
Resource
State
Representational State Transfer
your application can be Discoverable
your application can be Testable
Testability
HTTP
View Model
Control
too much code untested
HTTP
View Model
Control
Testability
too fragile and unreliableTestability
HTTP
View Model
Control
Testability
HTTP
Board
Game
Player
Position
Move
Js
HTTP
Board
Game
Player
Position
Move
Js
what about the view?Testability
your application can be Composable
your application can be Scalable
...so what Really means (for me) being RESTful?
now the Webcan talk about
chess