grokking rest (zendcon 2010)
DESCRIPTION
REST has become a hip buzzword of Web 2.0. But what makes an application RESTful? In this talk, Ben Ramsey reintroduces REST, uncovering each constraint that forms REST's principles. Ramsey explains how REST is a style for network-based software applications, emphasizing scalability and efficiency through separation of concerns and taking advantage of the Web as a platform for rich applications.TRANSCRIPT
![Page 1: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/1.jpg)
Ben Ramsey • Zend/PHP Conference & Expo • 4 Nov 2010Grokking REST
![Page 2: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/2.jpg)
What is REST?
![Page 3: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/3.jpg)
![Page 4: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/4.jpg)
#webdevgangsign
![Page 5: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/5.jpg)
![Page 6: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/6.jpg)
Representational State Transfer
![Page 7: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/7.jpg)
Client-server
![Page 8: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/8.jpg)
Stateless
![Page 9: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/9.jpg)
Cache
![Page 10: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/10.jpg)
Uniform Interface
![Page 11: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/11.jpg)
Layered System
![Page 12: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/12.jpg)
Code-on-demand
![Page 13: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/13.jpg)
RESTful Concepts
![Page 14: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/14.jpg)
Resources & URLs
![Page 15: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/15.jpg)
URLs do not matter
![Page 16: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/16.jpg)
![Page 17: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/17.jpg)
Using URLs as interfaces creates tight coupling
between the client & server
![Page 18: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/18.jpg)
http://api.example.org/user/getUser?u=ramsey
![Page 19: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/19.jpg)
Using URL templates creates tight coupling between the
client & server
![Page 20: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/20.jpg)
http://api.example.org/user/{username}/photos
![Page 21: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/21.jpg)
Your hypermedia format should expose the URLs that
represent your resources
![Page 22: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/22.jpg)
<?xml version="1.0" encoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xml:base="http://atom.example.org/"> <title>ramsey</title> <author> <name>ramsey</name> </author> <link rel="self" href="user/ramsey"/> <link rel="edit" type="application/atom+xml;type=entry" href="user/ramsey"/> <link rel="related" href="user/ramsey/content"/> <id>tag:example.org,2008:user/ramsey</id> <updated>2009-09-21T13:45:00Z</updated> <published>2008-05-23T16:23:34Z</published> <content type="xhtml"> <div class="vcard" xmlns="http://www.w3.org/1999/xhtml"> <a class="fn">Ben Ramsey</a> <span class="tel">123-456-7890</span> </div> </content></entry>
![Page 23: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/23.jpg)
Hypermedia
![Page 24: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/24.jpg)
application/json
![Page 25: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/25.jpg)
{ "id": "756315701", "name": "Ben Ramsey", "first_name": "Ben", "last_name": "Ramsey", "link": "http://www.facebook.com/ramseyben", "gender": "male", "locale": "en_US"}
![Page 26: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/26.jpg)
Hypermedia?
![Page 27: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/27.jpg)
No.
![Page 28: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/28.jpg)
application/facebook+json;type=user
![Page 29: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/29.jpg)
application/xml
![Page 30: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/30.jpg)
<?xml version="1.0" encoding="utf-8"?><user> <id>756315701</id> <name>Ben Ramsey</name> <first_name>Ben</first_name> <last_name>Ramsey</last_name> <link>http://www.facebook.com/ramseyben</link> <gender>male</gender> <locale>en_US</locale></user>
![Page 31: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/31.jpg)
Hypermedia?
![Page 32: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/32.jpg)
No.
![Page 33: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/33.jpg)
application/facebook+xml;type=user
![Page 34: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/34.jpg)
application/xhtml+xml
![Page 35: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/35.jpg)
Hypermedia?
![Page 36: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/36.jpg)
Yes!
![Page 37: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/37.jpg)
application/atom+xml
![Page 38: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/38.jpg)
Hypermedia?
![Page 39: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/39.jpg)
Yes!
![Page 40: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/40.jpg)
HATEOAS
![Page 41: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/41.jpg)
Grokking REST • Ben Ramsey
‣How does a client know what to do with resources?
‣How do you go to the “next” operation?
‣What are the URLs for creating subordinate resources?
‣Where is the contract for the service?
41
![Page 42: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/42.jpg)
Grokking REST • Ben Ramsey
Hypermedia as the Engine of Application State (HATEOAS)
‣Use links to allow clients to discover locations and operations
‣Link relations are used to express the possible options
‣Clients do not need to know URLs, so they can change
‣The entire application workflow is abstracted, thus changeable
‣The hypermedia type itself can be versioned if necessary
‣No breaking of clients if the implementation is updated!
42
![Page 43: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/43.jpg)
Why is REST so great?
![Page 44: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/44.jpg)
REST scales
![Page 45: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/45.jpg)
It’s extensible
![Page 46: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/46.jpg)
It’s evolvable
![Page 47: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/47.jpg)
Grokking REST • Ben Ramsey
Accept: application/vnd.myservice+xml;version=2
Use this style for versioning
47
![Page 48: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/48.jpg)
Grokking REST • Ben Ramsey
http://api.example.org/v2/foo
Not this style
48
![Page 49: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/49.jpg)
Grokking REST • Ben Ramsey
Accept: application/vnd.mytype+xml;version=1;q=0.5, application/vnd.myservice+xml;version=2
Clients can specify preferences
49
![Page 50: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/50.jpg)
It’s seamless
![Page 51: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/51.jpg)
Atom
![Page 52: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/52.jpg)
Entry Documentapplication/atom+xml;type=entry
Feed/Collection Documentapplication/atom+xml
Category Documentapplication/atomcat+xml
Service Documentapplication/atomsvc+xml
![Page 53: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/53.jpg)
GET / HTTP/1.1Host: atom.example.orgAccept: application/atomsvc+xml, application/atomcat+xml, application/atom+xml
HTTP/1.x 200 OKDate: Mon, 21 Sep 2009 16:33:45 GMTContent-‐Type: application/atomsvc+xml
<?xml version="1.0" encoding="utf-‐8"?><service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xml:base="http://atom.example.org/"> <workspace> <atom:title>Our Content Store</atom:title> <collection href="user"> <atom:title>Users</atom:title> <accept>application/atom+xml;type=entry</accept> <categories href="cat/user"/> </collection> <collection href="content"> <atom:title>Content</atom:title> <accept>application/atom+xml;type=entry</accept> <categories href="cat/content"/> </collection> </workspace></service>
![Page 54: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/54.jpg)
GET /user HTTP/1.1Host: atom.example.orgAccept: application/atom+xml
HTTP/1.x 200 OKDate: Mon, 21 Sep 2009 16:34:26 GMTContent-‐Type: application/atom+xml
<?xml version="1.0" encoding="utf-‐8"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xml:base="http://atom.example.org/"> <title>Users</title> <updated>2009-‐09-‐21T05:21:19Z</updated> <id>tag:example.org,2009-‐09:user</id> <app:collection href="user"> <title>Users</title> <app:accept>application/atom+xml;type=entry</app:accept> <app:categories href="cat/user"/> </app:collection> <link rel="first" href="user"/> <link rel="last" href="user?p=23"/> <link rel="next" href="user?p=2"/> <entry> ... </entry></feed>
![Page 55: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/55.jpg)
GET /cat/user HTTP/1.1Host: atom.example.orgAccept: application/atomcat+xml
HTTP/1.x 200 OKDate: Mon, 22 Sep 2009 09:39:26 GMTContent-‐Type: application/atomcat+xml
<?xml version="1.0"?><app:categories xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" fixed="yes" scheme="http://atom.example.com/cat/user"> <atom:category term="manager"/> <atom:category term="team"/> <atom:category term="user"/></app:categories>
![Page 56: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/56.jpg)
POST /user HTTP/1.1Host: atom.example.orgContent-‐Type: application/atom+xml;type=entry
<?xml version="1.0" encoding="utf-‐8"?><entry xmlns="http://www.w3.org/2005/Atom" xml:base="http://atom.example.org/"> <title>ramsey</title> <author> <name>ramsey</name> </author> <id>tag:example.org,2008:user/ramsey</id> <published>2008-‐05-‐23T16:23:34Z</published> <content type="xhtml"> <div class="vcard" xmlns="http://www.w3.org/1999/xhtml"> <a class="fn">Ben Ramsey</a> <span class="tel">123-‐456-‐7890</span> </div> </content></entry>
HTTP/1.x 201 CreatedDate: Mon, 22 Sep 2009 09:39:26 GMTLocation: http://atom.example.org/user/ramseyContent-‐Type: text/html
<html><body> <p>Your new resource was created <a href="http://atom.example.org/user/ramsey">here</a>.</p></body></html>
![Page 57: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/57.jpg)
Bringing it all together…
![Page 58: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/58.jpg)
Grokking REST • Ben Ramsey
Questions?
‣ I blog at benramsey.com.
‣ I tweet at @ramsey.
‣Please rate this presentation at joind.in/2284.
‣Find out more about REST by reading Architectural Styles and the Design of Network-based Software Architectures and “How I Explained REST to my Wife.”
‣My company is Moontoast. Check us out at moontoast.com. Follow us on Twitter and like us on Facebook.
58
![Page 59: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/59.jpg)
Grokking RESTCopyright © 2010 Ben Ramsey. Some rights reserved.Presented on November 4, 2010 at Zend/PHP Conference and Expo, Hyatt Regency Hotel, Santa Clara, CA.
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
For uses not covered under this license, please contact the author.
![Page 60: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/60.jpg)
Grokking REST • Ben Ramsey
Photo Credits
‣ Restful Summer, by Clear Inner Vision
‣ Roatan Beach - Perfect Day, by Janusz Leszczynski
‣ Tom Coates, by Patrick Lauke
‣ Web Developer Gang Sign, by Josh Lewis
‣ A Bar of Ivory Soap, by iirraa
‣ Albert Einstein, Public Domain, from Wikimedia Commons
‣ Separated, by Hansol Lee
‣ Stateless by Koesmanto Bong
‣ Cache County, Utah by J. Stephen Conn
‣ used to interface, by Tom Hensel
‣ Sedimentary Layers by Mark Thurman
‣ jeremy’s tie by Gitchel
‣ Sand Banks Sunset, by Clear Inner Vision
‣ Where I Teach, by Todd Ehlers
‣ Frosted Glass door, Goderham Building, by Rick Innis
‣ Drip Drops and the Spider Web, by Mike Bitzenhofer
‣ #110 Hypertext Transfer Protocol, by maako
‣ Before we had CAD, we had Lead!, by Wendell
60
![Page 61: Grokking REST (ZendCon 2010)](https://reader033.vdocuments.site/reader033/viewer/2022060108/554d1499b4c9052c5a8b5449/html5/thumbnails/61.jpg)
Grokking REST • Ben Ramsey
Photo Credits
‣ Molecule display, by Christian Guthier
‣ Conclusion, by Mark Cummins
61