Intro To REST: Joe Gregorio Google
Intro To REST: Joe Gregorio Google
Intro To REST: Joe Gregorio Google
Joe Gregorio
Google
REST is an
Architectural Style
Shaker
Architectural
Style
REST
Architectural HTTP
Style
HTTP
Why?
The Web
Request
Web
Client
Server
Response
Request
<!DOCTYPE HTML>
...
GET /news/ HTTP/1.1
Host: example.org
Accept-Encoding: compress, gzip
User-Agent: Python-httplib2
Resource = http://example.org/news/
GET /news/ HTTP/1.1
Host: example.org
Accept-Encoding: compress, gzip
User-Agent: Python-httplib2
Method = GET
Methods
Representation
...
<body>
<p><img src="logo.png">
<a href="/home/”>Home</a>
...
Hypertext
...
<head>
<link href="/css/b/base.css"
type="text/css"
rel="stylesheet">
...
Hypertext
...
<head>
<script src="utility.js"
type="text/javascript">
</script>
...
Code on Demand
...
Server: Apache
ETag: "85a1b765e8c01dbf872651d7a5"
Content-Type: text/html
Cache-Control: max-age=3600
...
Control Data
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
The Web
Request
Web
Client
Server
Response
The Web
Request
Origin
User Agent
Server
Response
Intermediaries
Origin
User Agent
Server
Intermediaries
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
Intermediaries
Origin
User Agent
Server
Proxies Gateways
Intermediaries
Origin
User Agent
Server
C C C C
Proxies Gateways
...
Server: Apache
ETag: "85a1b765e8c01dbf872651d7a5"
Content-Type: text/html
Cache-Control: max-age=3600
...
Cache Hit
Origin
User Agent
Server
C
Intermediary
Characteristics
• Resources
– URI
– Uniform Interface
• Methods
• Representation
• Protocol
– Client-Server
– Stateless
– Cacheable
– Layered
Benefits
Network Performance
• Efficiency
• Scalability
• User Perceived Performance
Benefits
Network Performance
• Efficiency
• Scalability
• User Perceived Performance
Benefits
Network Performance
• Efficiency
• Scalability
• User Perceived Performance
Benefits
Network Performance
• Efficiency
• Scalability
• User Perceived Performance
Other Benefits
• simplicity
• evolvability
• extensibility
• customizability
• configuration
• reusability
• visibility
• portability
• reliability
Benefits
Aren't Free
Comparison
XML-RPC
<?xml version="1.0"?>
<methodCall>
<methodName>getStateName</methodName>
...
HTTP/1.1 200 OK
Connection: close
Content-Length: 158
Content-Type: text/xml
Date: Fri, 17 Jul 1998 19:55:08 GMT
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<string>Maine</string>
...
POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Host: betty.userland.com
Content-Type: text/xml
Content-length: 181
<?xml version="1.0"?>
<methodCall>
<methodName>getStateName</methodName>
...
POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Host: betty.userland.com
Content-Type: text/xml
Content-length: 181
<?xml version="1.0"?>
<methodCall>
<methodName>getStateName</methodName>
...
Atom Publishing
Protocol
The Atom Publishing Protocol (AtomPub) is
an application-level protocol for publishing and
editing Web resources. The protocol is based
on HTTP transfer of Atom-formatted
representations. The Atom format is
documented in the Atom Syndication Format.
[RFC 5023]
Service Document
...
<img src='/image/big-image.png'>
...
Image
HTTP/1.1 200 Ok
Date: Thu, 15 Aug 2008 23:26:31 GMT
Server: Apache
Content-Length: 50753
Cache-Control: max-age=2592000
...
HTML
...
<img src='/image/big-image-2.png'>
...
Further Reading
● RFC 2616
● RFC 3986
of Network-based Software
Architectures
● Caching Tutorial
Intro to REST
Joe Gregorio
Google
So let's begin.
REST is an
Architectural Style
What is REST?
=============
http://www.flickr.com/photos/worobod/322627448/
CC Attribution
Request
Web
Client
Server
Response
<!DOCTYPE HTML>
... 9
Resource = http://example.org/news/
10
Method = GET
11
Representation
13
Hypertext
14
Hypertext
15
Code on Demand
16
Control Data
17
So now that we've reviewed those parts of HTTP let's look at the
characteristics of a RESTful protocol:
Request
Web
Client
Server
Response
24
Request
Origin
User Agent
Server
Response
25
Origin
User Agent
Server
Intermediaries
26
Origin
User Agent
Server
Proxies Gateways
29
Origin
User Agent
Server
C C C C
Proxies Gateways
30
31
Origin
User Agent
Server
C
Intermediary
32
34
35
36
37
Aren't Free
39
XML-RPC
41
POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Host: betty.userland.com
Content-Type: text/xml
Content-length: 181
<?xml version="1.0"?>
<methodCall>
<methodName>getStateName</methodName>
...
42
<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<string>Maine</string>
43
...
<?xml version="1.0"?>
<methodCall>
<methodName>getStateName</methodName>
...
44
Is it safe? No.
It is idempotent? No.
Cacheable? No.
POST /RPC2 HTTP/1.0
User-Agent: Frontier/5.1.2 (WinNT)
Host: betty.userland.com
Content-Type: text/xml
Content-length: 181
<?xml version="1.0"?>
<methodCall>
<methodName>getStateName</methodName>
...
45
46
Service Document
47
48
50
51
53
54
55
Long-lived Images
56
...
<img src='/image/big-image.png'>
...
57
Image
HTTP/1.1 200 Ok
Date: Thu, 15 Aug 2008 23:26:31 GMT
Server: Apache
Content-Length: 50753
Cache-Control: max-age=2592000
...
58
30 days
HTML
...
<img src='/image/big-image-2.png'>
...
59
● RFC 2616
● RFC 3986
of Network-based Software
Architectures
● Caching Tutorial
60
http://www.mnot.net/cache_docs/