Upload
alessandro-nadalin
View
3.212
Download
2
Embed Size (px)
DESCRIPTION
A brief "excursus" on the REST architectural style, with antipatterns and examples based on th
Citation preview
PHP.TO.START, July 11 2011 - Turin
RESTin peace
AGENDA
● Vol. 1: REST in a nutshell○Tenets○Antipatterns
● Vol. 2: To the rescue○HTTP cache○HATEOAS
PHP.TO.START, July 11 2011 - Turin
Sorry for the ugly slide.
There will be others.Really sorry.
PHP.TO.START, July 11 2011 - Turin
REST in a nutshell:
1. Client <> ServerPHP.TO.START, July 11 2011 - Turin
REST in a nutshell:
2. Stateless
PHP.TO.START, July 11 2011 - Turin
3. Cacheable
REST in a nutshell:
PHP.TO.START, July 11 2011 - Turin
REST in a nutshell:
4. Layered systemPHP.TO.START, July 11 2011 - Turin
REST in a nutshell:
5. Uniform interface
PHP.TO.START, July 11 2011 - Turin
And obviously nobody had a clue
PHP.TO.START, July 11 2011 - Turin
ANTIPATTERNS
PHP.TO.START, July 11 2011 - Turin
1URIs
PHP.TO.START, July 11 2011 - Turin
"REST is about
cool URI design"
http://apple.com/users/1/licenses/4.json
PHP.TO.START, July 11 2011 - Turin
"REST is about
cool URI design"
http://apple.com/users/1/licenses/4.json
PHP.TO.START, July 11 2011 - Turin
http://apple.com/site/en_US/showUsers.jsp?uid=1&license=4
is OK too
PHP.TO.START, July 11 2011 - Turin
but
PHP.TO.START, July 11 2011 - Turin
cool URIs help youthink in term of resources
David Zuelke
PHP.TO.START, July 11 2011 - Turin
2URIs (bis)
PHP.TO.START, July 11 2011 - Turin
GET /users POST /users PUT /users/{id} DELETE /users/{id} ...
REST follows a URI schema
PHP.TO.START, July 11 2011 - Turin
GET /users POST /users PUT /users/{id} DELETE /users/{id} ...
REST follows a URI schema
PHP.TO.START, July 11 2011 - Turin
what if you change yourURL?
PHP.TO.START, July 11 2011 - Turin
Yeah, client is broken
PHP.TO.START, July 11 2011 - Turin
RESTful clients shouldbe driven by service'shypermedia controls
Roy Fielding : http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
PHP.TO.START, July 11 2011 - Turin
HATEOAS
PHP.TO.START, July 11 2011 - Turin
3POST is cool
PHP.TO.START, July 11 2011 - Turin
said SOAP 1.1
PHP.TO.START, July 11 2011 - Turin
said SOAP 1.1
PHP.TO.START, July 11 2011 - Turin
loosing meaningful verbs at the protocol level
PHP.TO.START, July 11 2011 - Turin
loosing meaningful verbs at the protocol level
nothing cacheable by default
PHP.TO.START, July 11 2011 - Turin
loosing meaningful verbs at the protocol level
nothing cacheable by default
what about bookmarking?
PHP.TO.START, July 11 2011 - Turin
4500 is your friend
PHP.TO.START, July 11 2011 - Turin
said SOAP( again )
PHP.TO.START, July 11 2011 - Turin
GET /users/300Host: www.example.com
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 500 Internal Server ErrorEtag: 1234X-Powered-By: php/5.3...
The record cannot be found
GET /users/300Host: www.example.com
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 500 Internal Server ErrorEtag: 1234X-Powered-By: php/5.3...
The record cannot be found
GET /users/300Host: www.example.com
PHP.TO.START, July 11 2011 - Turin
The HTTP protocol is awesome,and lets you return meaningful anduniversally-understood status codes
PHP.TO.START, July 11 2011 - Turin
404 Not Found
PHP.TO.START, July 11 2011 - Turin
404 Not Found
OMG Link is broken?
PHP.TO.START, July 11 2011 - Turin
202 Accepted
PHP.TO.START, July 11 2011 - Turin
202 Accepted
You get an immediate OK, and the operation will hopefully complete
PHP.TO.START, July 11 2011 - Turin
Pause
PHP.TO.START, July 11 2011 - Turin
World Wide Web
PHP.TO.START, July 11 2011 - Turin
the largest data-exchange network on the planet
PHP.TO.START, July 11 2011 - Turin
And meanwhile, at Facebook...
12TB of new data every day(1 year ago)
500 million users
PHP.TO.START, July 11 2011 - Turin
And meanwhile, at Google...
1 billion unique monthly googlers
PHP.TO.START, July 11 2011 - Turin
via HTTP, baby!
PHP.TO.START, July 11 2011 - Turin
HTTP in a nutshell:
1. Client <> ServerPHP.TO.START, July 11 2011 - Turin
HTTP in a nutshell:
2. Stateless
PHP.TO.START, July 11 2011 - Turin
http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
3. widespread cache spec
HTTP in a nutshell:
PHP.TO.START, July 11 2011 - Turin
HTTP in a nutshell:
4. Layered systemOrigin server
Reverse proxy
Great chinese (fire)wall
Company proxy
Lao Tze Song using Firefox 5
PHP.TO.START, July 11 2011 - Turin
HTTP in a nutshell:
5. it is the uniform interfacebetween clients and servers
PHP.TO.START, July 11 2011 - Turin
HTTP bleeds REST
PHP.TO.START, July 11 2011 - Turin
1.
caching & scalability
PHP.TO.START, July 11 2011 - Turin
Local
Shared/proxy
Shared/reverse proxy
Types of cache
PHP.TO.START, July 11 2011 - Turin
Local
Shared/proxy
Shared/reverse proxy
Types of cache
PHP.TO.START, July 11 2011 - Turin
PHP.TO.START, July 11 2011 - Turin
Local
Shared/proxy
Shared/reverse proxy
Types of cache
PHP.TO.START, July 11 2011 - Turin
PHP.TO.START, July 11 2011 - Turin
Local
Shared/proxy
Shared/reverse proxy
Types of cache
PHP.TO.START, July 11 2011 - Turin
PHP.TO.START, July 11 2011 - Turin
on the server side
PHP.TO.START, July 11 2011 - Turin
Caching withExpiration(example)
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 200 OKHost: www.example.comExpires: 0
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 200 OKHost: www.example.comExpires: 0
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 200 OKHost: www.example.comExpires: Tue, 31 Jan 2011 01:00 GMT
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public
Cacheable for 60 seconds
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public
Cacheable by both local and shared caches
PHP.TO.START, July 11 2011 - Turin
but hey, you say
PHP.TO.START, July 11 2011 - Turin
HTTP's cache fails when dealing with really dynamic pages, because consumers will always have to hit the
origin server, although a part of the page would be cacheable ( header and footer, for example )
PHP.TO.START, July 11 2011 - Turin
Nope
Nope
PHP.TO.START, July 11 2011 - Turin
ESI was built for thathttp://www.w3.org/TR/esi-lang
PHP.TO.START, July 11 2011 - Turin
<esi:include src="http://php2start.com/talks/1" />
PHP.TO.START, July 11 2011 - Turin
<esi:include src="http://php2start.com/talks/1" />
PHP.TO.START, July 11 2011 - Turin
<esi:include src="http://php2start.com/talks/1" />
PHP.TO.START, July 11 2011 - Turin
1s (tweets)
3600 post
PHP.TO.START, July 11 2011 - Turin
<esi:include src='tweets.html' />
<esi:include src='article/12.html' />
PHP.TO.START, July 11 2011 - Turin
So what does HTTP cache is meant to solve?
PHP.TO.START, July 11 2011 - Turin
Less work
PHP.TO.START, July 11 2011 - Turin
because the hard work is delegated to the browser/proxy
http://www.flickr.com/photos/snakphotography/5004775320/sizes/o/in/photostream/
PHP.TO.START, July 11 2011 - Turin
evolve
PHP.TO.START, July 11 2011 - Turin
because cache is abstracted from the application
PHP.TO.START, July 11 2011 - Turin
loose coupling
PHP.TO.START, July 11 2011 - Turin
because caching is bound to the protocol, HTTP, not to your implementation ( Sf, RoR, Django )
PHP.TO.START, July 11 2011 - Turin
2.
adaptability & durability
PHP.TO.START, July 11 2011 - Turin
Hypermediaanother long-time friend
PHP.TO.START, July 11 2011 - Turin
Linksoutrageously semplifying
PHP.TO.START, July 11 2011 - Turin
<link rel="payment" href="/checkout" type="text/html" ... />
PHP.TO.START, July 11 2011 - Turin
<link rel="payment" href="/checkout" type="text/html" ... />
PHP.TO.START, July 11 2011 - Turin
<link rel="payment" href="/checkout" type="text/html" ... />
PHP.TO.START, July 11 2011 - Turin
<link rel="payment" href="/checkout" type="text/html" ... />
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1
POST /usersHost: www.example.com
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1
POST /usersHost: www.example.com
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1
POST /usersHost: www.example.com
PHP.TO.START, July 11 2011 - Turin
HTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1
POST /usersHost: www.example.com
PHP.TO.START, July 11 2011 - Turin
consumers of your API are able to followthe changes of your design
PHP.TO.START, July 11 2011 - Turin
everything seems cool
But why REST?
PHP.TO.START, July 11 2011 - Turin
Pros
PerformancesPHP.TO.START, July 11 2011 - Turin
Pros
Scalability
PHP.TO.START, July 11 2011 - Turin
Pros
Durability
PHP.TO.START, July 11 2011 - Turin
amazon.it
PHP.TO.START, July 11 2011 - Turin
PHP.TO.START, July 11 2011 - Turin
REST-IThttps://groups.google.com/forum/#!forum/rest-it
Alessandro Nadalin
Alessandro Nadalinodino.org
Alessandro Nadalinodino.org
@_odino_
Alessandro Nadalinodino.org
@_odino_
Thanks
Alessandro Nadalinodino.org
@_odino_
Creditshttp://www.flickr.com/photos/larachris/16564077/sizes/o/in/photostream/
http://www.flickr.com/photos/ashatenbroeke/4367373081/sizes/z/in/photostream/http://www.flickr.com/photos/yourdon/3140270189/sizes/l/in/photostream/http://www.flickr.com/photos/jox1989/4964706072/sizes/l/in/photostream/http://www.flickr.com/photos/brainfg/168506259/sizes/o/in/photostream/
http://www.flickr.com/photos/norte_it/3897091546/sizes/o/in/photostream/http://www.zdnet.com/blog/service-oriented/soap-versus-rest-a-matter-of-style/3568
http://www.flickr.com/photos/turtlemom_nancy/2046347762/sizes/l/in/photostream/http://www.flickr.com/photos/juanpg/3333385784/sizes/z/in/photostream/http://www.flickr.com/photos/congvo/301678287/sizes/l/in/photostream/
http://www.flickr.com/photos/ihasb33r/2573196546/sizes/z/in/photostream/http://www.flickr.com/photos/martin_heigan/4544138976/sizes/o/in/photostream/
http://www.flickr.com/photos/cknara/4195099999/sizes/o/in/photostream/http://www.flickr.com/photos/1080p/3076529265/sizes/l/in/photostream/
http://www.flickr.com/photos/adamrice/280300202/sizes/l/in/photostream/http://www.flickr.com/photos/tomer_a/541411897/sizes/o/in/photostream/http://www.flickr.com/photos/subpra/4514008262/sizes/l/in/photostream/
http://www.flickr.com/photos/lippincott/2539720043/sizes/l/in/photostream/http://www.flickr.com/photos/rawryder/5086090931/sizes/l/in/photostream/http://www.flickr.com/photos/robboudon/5312731161/sizes/l/in/photostream/
http://www.flickr.com/photos/bc-burnslibrary/4158243488/sizes/o/in/photostream/http://www.flickr.com/photos/13606325@N08/2416993706/sizes/o/in/photostream/
http://www.flickr.com/photos/neothezion/5135841069/sizes/l/in/photostream/http://www.flickr.com/photos/planetschwa/2494067809/http://www.flickr.com/photos/thomasthomas/258931782/
http://www.flickr.com/photos/rustyboxcars/2629631562/sizes/l/in/photostream/http://www.flickr.com/photos/ell-r-brown/4138727474/sizes/l/in/photostream/http://www.flickr.com/photos/noah123/5082076630/sizes/z/in/photostream/http://www.flickr.com/photos/jungle_boy/220181177/sizes/l/in/photostream/
http://www.flickr.com/photos/prettydaisies/872539081/sizes/l/in/photostream/http://www.flickr.com/photos/kaptainkobold/76256150/sizes/o/in/photostream/
http://www.flickr.com/photos/uomoincravatta/1438372865/sizes/z/in/photostream/
PHP.TO.START, July 11 2011 - Turin