Professional Documents
Culture Documents
Cesare Pautasso
Faculty of Informatics
University of Lugano
http://www.pautasso.info
c.pautasso@ieee.org
31.3.2009
Web
Browser
HTML
HTTP
Web
Server
XML
WSDL
Server
(HTTP)
Web Services and Service Oriented Architectures
2009 Cesare Pautasso
PO-XML
JSON
Client
HTTP
WADL
Web
Server
XML
WSDL
Server
(HTTP)
Web Services and Service Oriented Architectures
2009 Cesare Pautasso
Enterprise Computing
CICS
IMS
31.3.2009
HTTP
232 pages
31.3.2009
PUT
Contents
GET
What is REST?
RESTful Service Design
Comparison WS-* vs. REST
Discussion
Outlook
31.3.2009
POST
DELETE
Web Server
Database
(Web Browser)
GET /book?ISBN=222
POST /order
301 Location: /order/612
PUT /order/612
31.3.2009
SELECT *
FROM books
WHERE isbn=222
INSERT
INTO orders
UPDATE orders
WHERE id=612
CRUD
CREATE
REST
POST
READ
GET
UPDATE
PUT
DELETE
DELETE
31.3.2009
Create a
sub resource
Retrieve the current
state of the resource
Initialize or update the
state of a resource
at the given URI
Clear a resource,
after the URI is no
longer valid
10
URI
Uniform Resource Identifier
Internet Standard for resource naming and identification
(originally from 1994, revised until 2005)
Examples:
http://tools.ietf.org/html/rfc3986
URI Scheme
Authority
Path
https://www.google.ch/search?q=rest&start=10#1
Query
Fragment
11
http://maps.google.com/maps?f=q&hl=en&q=lugano,
+switzerland&layer=&ie=UTF8&z=12&om=1&iwloc=addr
31.3.2009
12
31.3.2009
GET /book?isbn=24&action=delete
DELETE /book/24
13
14
15
JSON Example
Array
31.3.2009
{"riskReportResponseData":
[
{"year":2000,
"report":{
"policyCount":34,
"totalClaimValue":279080.37,
"totalInsuredValue":2996932.42,
"claimCount":29}
}
,
{"year":2001,
"report":{
"policyCount":3906,
"totalClaimValue":125591.37,
"totalInsuredValue":8.92368089e7,
"claimCount":31
}}
]
Value
String
}
Object
Object
16
REST Strengths
Simplicity
Uniform interface is immutable (no problem of breaking clients)
HTTP/POX is ubiquitous (goes through firewalls)
Stateless/Synchronous interaction
Proven scalability
after all the Web works, caching, clustered server farms for QoS
Perceived ease of adoption (light infrastructure)
just need a browser to get started - no need to buy WS-*
middleware
Grassroots approach
Leveraged by all major Web 2.0 applications
85% clients prefer Amazon RESTful API (*)
Google does no longer support its SOAP/WSDL API
(*) http://www.oreillynet.com/pub/wlg/3005
31.3.2009
17
31.3.2009
18
REST Weaknesses
Confusion (high REST vs. low REST)
Is it really 4 verbs? (HTTP 1.1. has 8 verbs: HEAD, GET, POST,
PUT, DELETE, TRACE, OPTIONS, and CONNECT)
Mapping REST-style synchronous semantics on top of back end
systems creates design mismatches (when they are based on
asynchronous messaging or event driven interaction)
Cannot deliver enterprise-style -ilities beyond HTTP/SSL
Challenging to identify and locate resources appropriately in all
applications
Apparent lack of standards (other than URI, HTTP, XML, MIME,
HTML)
Semantics/Syntax description very informal (user/human oriented)
31.3.2009
19
POST
DELETE
31.3.2009
GET
/loan
/balance
/client
/book
/order
/soap
20
Creating a poll (transfer the state of a new poll on the Doodle service)
GET /poll/090331x
POST /poll
<options>A,B,C</options>
200 OK
201 Created
Location: /poll/090331x
<options>A,B,C</options>
Reading a poll (transfer the state of the poll from the Doodle service)
31.3.2009
21
POST /poll/090331x/vote
GET /poll/090331x
<name>C. Pautasso</name>
<choice>B</choice>
200 OK
201 Created
Location:
/poll/090331x/vote/1
31.3.2009
<options>A,B,C</options>
<votes><vote id=1>
<name>C. Pautasso</name>
<choice>B</choice>
</vote></votes>
22
PUT /poll/090331x/vote/1
GET /poll/090331x
<name>C. Pautasso</name>
<choice>C</choice>
200 OK
200 OK
31.3.2009
<options>A,B,C</options>
<votes><vote id=/1>
<name>C. Pautasso</name>
<choice>C</choice>
</vote></votes>
Web Services and Service Oriented Architectures
2009 Cesare Pautasso
23
DELETE /poll/090331x
GET /poll/090331x
200 OK
24
Content-Type Negotiation
3. Exception Handling
31.3.2009
25
26
PUT /resource/{id}
Problem: How to ensure resource {id} is unique?
(Resources can be created by multiple clients concurrently)
POST /resource
201 Created
Location: /resource/{id}
Solution: let the server compute the unique id
31.3.2009
27
GET /resource
Accept: text/html, application/xml,
application/json
1. The client lists the set of format (MIME types) that it understands
200 OK
Content-Type: application/json
2. The server chooses the most appropriate one for the reply
31.3.2009
28
GET /resource
Accept: text/html, application/xml,
application/json
The specific URI points to a specific representation format using the postfix
GET /resource.html
GET /resource.xml
GET /resource.json
Warning: This is a conventional best practice (not a standard)
31.3.2009
29
Exception Handling
Learn to use HTTP Standard Status Codes
100
200
201
202
203
204
205
206
300
301
302
303
304
305
307
Continue
OK
Created
Accepted
Non-Authoritative
No Content
Reset Content
Partial Content
Multiple Choices
Moved Permanently
Found
See Other
Not Modified
Use Proxy
Temporary Redirect
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
500
501
502
503
504
505
Bad Request
Unauthorized
Payment Required
Forbidden
Not Found
5xx Servers
Method Not Allowed
Not Acceptable
Proxy Authentication Required
Request Timeout
Conflict
Gone
Length Required
Precondition Failed
Request Entity Too Large
Request-URI Too Long
Unsupported Media Type
Requested Range Not Satisfiable
Expectation Failed
fault
30
31.3.2009
31
31.3.2009
WS-*
REST
Middleware
Interoperability
Standards
Architectural
style for
the Web
32
Technology Comparison
31.3.2009
33
Web Server
Database
(Web Browser)
GET /book?ISBN=222
PUT /order
301 Location: /order/612
POST /order/612
31.3.2009
SELECT *
FROM books
WHERE isbn=222
INSERT
INTO orders
UPDATE orders
WHERE id=612
34
Web Server
(Stub Object)
POST /soap/router
POST /soap/router
POST /soap/router
31.3.2009
Web Service
Implementation
return getBook(222)
return new Order()
order.setCustomer(x)
35
31.3.2009
SOAP (WS-*)
SMTP
HTTP
POST
MQ
Resource URI
Endpoint URI
Application
Application
36
REST as a connector
Stream
File Transfer
Shared Data
31.3.2009
REpresentational
State Transfer
Web Services and Service Oriented Architectures
2009 Cesare Pautasso
37
Stateless or Stateful?
(*) Each client request to the server must contain all information needed to understand the request, without referring to any
stored context on the server. Of course the server stores the state of its resources, shared by all clients.
31.3.2009
38
What about
service description?
31.3.2009
39
31.3.2009
40
Although HTTP is a
synchronous protocol, it can be
used to simulate a message
queue.
POST /queue
202 Accepted
Location:
/queue/message/1230213
GET /queue/message/1230213
DELETE
/queue/message/1230213
31.3.2009
41
Noah Mendelsohn
Christopher Ferris
James Snell
IBM
31.3.2009
42
31.3.2009
43
2007 IBM Corporation
Interpretations differ
Synchronous vs. Asynchronous
Uniform Interface never
changes
XML Schema
HTTP
31.3.2009
44
31.3.2009
45
46
31.3.2009
47
References
Leonard Richardson, Sam Ruby, RESTful Web Services, OReilly, May 2007
Roy Fielding, Architectural Styles and the Design of Network-based Software
Architectures, University of California, Irvine, 2000, Chapter 5
http://roy.gbiv.com/pubs/dissertation/fielding_dissertation.pdf
W3C Workshop on Web of Services for Enterprise Computing,
27-28 February 2007 http://www.w3.org/2007/01/wos-ec-program.html
Sun, JSR311 - Java API for RESTful Web Services
http://jcp.org/en/jsr/detail?id=311
Marc J. Hadley (Sun), Web Application Description Language (WADL)
https://wadl.dev.java.net/
Thomas Bayer, REST Web Services Eine Einfuehrung (November 2002)
http://www.oio.de/public/xml/rest-webservices.pdf
Michi Henning, The Rise and Fall of CORBA, Component Technologies, Vol. 4. No. 5,
June 2006
Stefan Tilkov, REST Patterns and Antipatterns, JAOO 2008
Cesare Pautasso, Erik Wilde, From SOA to REST, WWW 2009 Tutorial
Jacob Nielsen, URI are UI, http://www.useit.com/alertbox/990321.html
Douglas Crockford, JSON - the fat-free alternative to XML, XML 2006.
Cesare Pautasso, Olaf Zimmermann, Frank Leymann, RESTful Web Services vs. Big
Web Services: Making the Right Architectural Decision, 17th International World
Wide Web Conference (WWW2008), Bejing,China, April 2008.
http://www.jopera.org/docs/publications/2008/restws
31.3.2009
48