Académique Documents
Professionnel Documents
Culture Documents
REST
(Representational State Transfer)
Roger L. Costello
Timothy D. Kehoe
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 2
Overview
• The Web's simple set of operations,
i.e., the Web's API
• The Web's fundamental components
• REST
• Questions and Answers
• The REST design pattern (summary)
• References
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 3
Terminology:
Header and Payload
POST This information
POST//HTTP/1.1
HTTP/1.1
Host:
Host:http://www.amazon.com
http://www.amazon.com (the HTTP data)
Book: is called the
Book: DaVince Code Book:DaDaVince
VinceCode
Code
Credit Card: Visa
Number: 123-45-6789 Credit
CreditCard:
Card:Visa
Visa
HTTP header
Expiry: 12-04-06
Number:
Number:123-45-6789
123-45-6789
Expiry:
Expiry:12-04-06
12-04-06 Amazon
Web Server
FIREWALL
Item: Woodworking set
Credit Card: Visa
Item:
Item:Woodworking
Woodworkingset
set
Number: 123-45-6789 Credit
CreditCard:
Card:Visa
Visa
Expiry: 12-04-06
Number:
Number:123-45-6789
123-45-6789
Expiry: 12-04-06
Expiry: 12-04-06
fundamental!
– This message is rejected!
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 10
Web Message
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 12
Letter Analogy
• Why do Web components base their decisions solely
on information in the HTTP header?
• My company has a receiving warehouse. All letters
and packages go there first, and from there they are
distributed.
• No one in the receiving warehouse may look inside
any letter or package. All decisions about what to do
with letters and packages must be made purely by
looking at the addressing on the outside. Any attempt
to peek inside of letters and packages is a violation of
Federal Law (U.S.).
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 13
REST
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 14
What is REST?
" REST " was coined by Roy Fielding
in his Ph.D. dissertation [1] to describe
a design pattern for implementing
networked systems.
[1] http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 15
Why is it called
"Representational State Transfer? "
http://www.boeing.com/aircraft/747
Client Resource
Fuel requirements
Maintenance schedule
...
Boeing747.html
- Roy Fielding
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 17
Learn by Example
• The REST design pattern is best explained
with an example.
• I will present an example of a company
deploying three Web services using the
REST design pattern.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 20
Web Server
HTTP GET request URL 2 Part
Response
HTTP response Data
(HTML/XML doc)
PO
HTTP POST (HTML/XML)
URL 3
PO
URL to submitted PO HTTP response
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 22
REST Fundamentals
• Create a resource for every service.
• Identify each resource using a URL.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 24
Note that the parts list has links to get detailed info about each part.
This is a key feature of the REST design pattern. The client transfers
from one state to the next by examining and choosing from among
the alternative URLs in the response document.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 25
REST Fundamentals
• The data that a Web service returns
should link to other data. Thus,
design your data as a network of
information.
• Contrast with OO design, which
says to encapsulate information.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 26
Again observe how this data is linked to still more data - the
specification for this part may be found by traversing the hyperlink.
Each response document allows the client to drill down to get
more detailed information.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 28
Question
What if Parts Depot has a million parts, will there be a million
static pages? For example:
http://www.parts-depot/parts/000000
http://www.parts-depot/parts/000001
...
http://www.parts-depot/parts/999999
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 30
Answer
We need to distinguish between a logical and a physical entity.
The above URLs are logical. They express what resource is desired.
Quite likely, Parts Depot will store all parts data in a database.
Code at the Parts Depot web site will receive each logical URL
request, parse it to determine which part is being requested,
query the database, and generate the part response document
to return to the client.
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 31
Answer (cont.)
Contrast the above logical URLs with these physical URLs:
http://www.parts-depot/parts/000000.html
http://www.parts-depot/parts/000001.html
...
http://www.parts-depot/parts/999999.html
Question
What if I have a complex query?
For example:
Show me all parts whose unit cost is under $0.50
and for which the quantity is less than 10
Answer
For complex queries, Parts Depot will provide a service
(resource) for a client to retrieve a form that the client then fills
in.
When the client hits "Submit" the browser will gather up the
client’s responses and generate a URL based on the responses.
Thus, oftentimes the client doesn't generate the URL (think about
using Amazon - you start by entering the URL to amazon.com;
from then on you simply fill in forms, and the URLs are
automatically created for you).
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 34
Summary of the
REST Design Pattern
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 35
References
Copyright © [2005]. Roger L. Costello, Timothy D. Kehoe. All Rights Reserved. 39
References
• Paul Prescod has written several excellent
articles on REST:
– Second Generation Web Services
• http://www.xml.com/pub/a/2002/02/06/rest.html
– REST and the Real World
• http://www.xml.com/pub/a/2002/02/20/rest.html
– SOAP, REST and Interoperability
• http://www.prescod.net/rest/standardization.html
– Evaluating XML for Protocol Control Data
• http://www.prescod.net/xml/envelopes/