grokking the rest architectural style
DESCRIPTION
REST has become the hip, new buzzword of Web 2.0. But what makes an application RESTful? Pretty URLs? XML over HTTP? Any service that's not SOAP? In all the hype, the definition of REST has become clouded and diluted. Forget what you thought you knew about REST. In this talk, Ben Ramsey reintroduces REST, placing it under a microscope, uncovering each constraint that forms REST's crucial 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 Internet applications.TRANSCRIPT
![Page 1: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/1.jpg)
Ben Ramsey ■ Dutch PHP Conference ■ 12 June 2009
Grokking theREST Architectural Style
![Page 2: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/2.jpg)
Yes.
I am this guy.
![Page 3: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/3.jpg)
REST
Roatan Beach - Perfect Day, by Janusz Leszczynski
![Page 4: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/4.jpg)
Tom Coates, by Patrick Lauke
Is it about pretty URLs?
![Page 5: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/5.jpg)
Web Developer Gang Sign, by Josh Lewis
How about XML over HTTP?
#webdevgangsign
![Page 6: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/6.jpg)
A Bar of Ivory Soap, by iirraa
Any web service that’s not SOAP?
![Page 7: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/7.jpg)
RepresentationalState Transfer
Restful Summer, by Clear Inner Vision
![Page 8: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/8.jpg)
Theoryof REST
Public Domain, from Wikimedia Commons
![Page 9: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/9.jpg)
REST defines a style by which a resource’s state may be transferred using a representation of that resource.
REST defines a style by which a resource’s state may be transferred using a representation of that resource.
REST defines a style by which a resource’s state may be transferred using a representation of that resource.
![Page 10: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/10.jpg)
Client-serverSeparated, by Hansol Lee
![Page 11: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/11.jpg)
Stateless
Stateless by Koesmanto Bong
![Page 12: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/12.jpg)
Cache
Cache County, Utah by J. Stephen Conn
![Page 13: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/13.jpg)
used to interface, by Tom Hensel
Uniform Interface
1.Identification of resources2.Representation of resources3.Linked resources4.Resource metadata
![Page 14: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/14.jpg)
Layered
Sedimentary Layers by Mark Thurman
![Page 15: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/15.jpg)
Code-on-demandjeremyʼs tie by Gitchel
![Page 16: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/16.jpg)
Sand Banks Sunset, by Clear Inner Vision
RESTful Benefits
Improved response time & reduced server load
Improves server scalability
Requires less client-side software
Depends less on vendor software
No need for resource discovery
Better long-term compatibility & evolvability than RPC
![Page 17: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/17.jpg)
A Real-World Analogy
Money!, by Tracy Olson
![Page 18: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/18.jpg)
RESTfulPractice
Public Domain, from Wikimedia Commons
![Page 19: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/19.jpg)
Drip Drops and the Spider Web, by Mike Bitzenhofer
“[REST] is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through an application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.” — Roy Fielding
![Page 20: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/20.jpg)
Hypertext Transfer Protocol
#110 Hypertext Transfer Protocol, by maako
URIs provide unique addresses
Constrained interface with methods and content types
Transactions are atomic
Built-in support for layering
Provides for cache control
![Page 21: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/21.jpg)
HTTP Interface
#110 Hypertext Transfer Protocol, by maako
Methods
GETPUTPOSTDELETE
Cut & Paste
CopyPaste OverPaste AfterCut
![Page 22: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/22.jpg)
Content Types
#110 Hypertext Transfer Protocol, by maako
HTTP supports content types through the Content-Type header
A single resource can be transferred in various content types
Content negotiation used to tell the server what type to return to the client
REST community doesn’t care for content negotiation
![Page 23: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/23.jpg)
#110 Hypertext Transfer Protocol, by maako
1
POST /content HTTP/1.1Host: example.orgContent-Type: application/xml
2
HTTP/1.x 201 CreatedDate: Thu, 13 November 2008 16:43:56 GMTLocation: /content/1234
Lifecycle of a Resource
![Page 24: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/24.jpg)
#110 Hypertext Transfer Protocol, by maako
3
GET /content/1234 HTTP/1.1Host: example.org
4
HTTP/1.x 200 OKDate: Thu, 13 November 2008 16:44:13 GMTContent-Type: application/xml
Lifecycle of a Resource
![Page 25: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/25.jpg)
#110 Hypertext Transfer Protocol, by maako
5
PUT /content/1234 HTTP/1.1Host: example.orgContent-Type: application/xml
Lifecycle of a Resource
6
HTTP/1.x 200 OKDate: Thu, 13 November 2008 16:48:26 GMTContent-Type: application/xml
![Page 26: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/26.jpg)
#110 Hypertext Transfer Protocol, by maako
7
DELETE /content/1234 HTTP/1.1Host: example.org
Lifecycle of a Resource
8
HTTP/1.x 204 No ContentDate: Thu, 13 November 2008 16:50:47 GMT
![Page 27: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/27.jpg)
Resource-oriented Architecture
Where I Teach, by Todd Ehlers
1. Represent itself to the client
2. Transition from one state to the next
3. Destroy itself
Additionally, the system knows how to create a resource.
![Page 28: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/28.jpg)
Resource-oriented Architecture
Where I Teach, by Todd Ehlers
Resources are addressable
Resources have no state
Resources are connected
Resources share the same interface
![Page 29: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/29.jpg)
Resource-oriented Architecture
Where I Teach, by Todd Ehlers
Query string parameters appropriate in some cases
Pragmatic use of URIs instead of using HTTP headers
RPC-style APIs are avoided
Representation should have links
URI templates specify URI families
![Page 30: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/30.jpg)
Resource-oriented Architecture
Where I Teach, by Todd Ehlers
Should expose many URIs
Session cookies are not RESTful
Combined resources are RESTful only if represented as a URI
URIs should facilitate “cut & paste”
![Page 31: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/31.jpg)
Atom
A resource-oriented protocol for publishing documents that sits on top of HTTP
Molecule display, by Christian Guthier
![Page 32: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/32.jpg)
Atom
Entry Documentapplication/atom+xml;type=entry
Molecule display, by Christian Guthier
Feed (Collection) Documentapplication/atom+xml;type=feed
Category Documentapplication/atomcat+xml
Service Documentapplication/atomsvc+xml
![Page 33: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/33.jpg)
1
GET /index.atom HTTP/1.1Host: example.org
2
HTTP/1.x 200 OKDate: Thu, 13 November 2008 17:13:14 GMTContent-Type: application/atomsvc+xml
Atom Resource Lifecycle
Molecule display, by Christian Guthier
![Page 34: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/34.jpg)
3
GET /archives.atom HTTP/1.1Host: example.org
4
HTTP/1.x 200 OKDate: Thu, 13 November 2008 17:13:46 GMTContent-Type: application/atom+xml;type=feed
Atom Resource Lifecycle
Molecule display, by Christian Guthier
![Page 35: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/35.jpg)
5
GET /categories.atom HTTP/1.1Host: example.org
6
HTTP/1.x 200 OKDate: Thu, 13 November 2008 17:13:48 GMTContent-Type: application/atomcat+xml
Atom Resource Lifecycle
Molecule display, by Christian Guthier
![Page 36: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/36.jpg)
7
POST /archives.atom HTTP/1.1Host: example.orgContent-Type: application/atom+xml;type=entry
8
HTTP/1.x 201 CreatedDate: Thu, 13 November 2008 17:16:32 GMTLocation: /archives/1234.atom
Atom Resource Lifecycle
Molecule display, by Christian Guthier
![Page 37: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/37.jpg)
9
10
HTTP/1.x 200 OKDate: Thu, 13 November 2008 17:16:36 GMTContent-Type: application/atom+xml;type=entry
Atom Resource Lifecycle
GET /archives/1234.atom HTTP/1.1Host: example.org
Molecule display, by Christian Guthier
![Page 38: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/38.jpg)
11
12
HTTP/1.x 200 OKDate: Thu, 13 November 2008 17:23:12 GMTContent-Type: application/atom+xml;type=entry
Atom Resource Lifecycle
PUT /archives/1234.atom HTTP/1.1Host: example.orgContent-Type: application/atom+xml;type=entry
Molecule display, by Christian Guthier
![Page 39: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/39.jpg)
13
14
HTTP/1.x 204 No ContentDate: Thu, 13 November 2008 19:34:29 GMT
Atom Resource Lifecycle
DELETE /archives/1234.atom HTTP/1.1Host: example.org
Molecule display, by Christian Guthier
![Page 40: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/40.jpg)
Resource-orientedDesign
1. Determine your resources
User Content
/users/users/{username}
/content/content/{ID}
Before we had CAD, we had Lead!, by Wendell
![Page 41: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/41.jpg)
2. Decide the methods for each resource
/users
GETPOST
/content
GETPOST
/users/{username}
GETPUTDELETE
/content/{ID}
GETPUTDELETE
Before we had CAD, we had Lead!, by Wendell
Resource-orientedDesign
![Page 42: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/42.jpg)
3. Link your resources
Before we had CAD, we had Lead!, by Wendell
Resource-orientedDesign
Users own content
Each user owns multiple content items
Each content item has one owner
![Page 43: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/43.jpg)
4. Determine your data schemas
Before we had CAD, we had Lead!, by Wendell
User Content
idusernamefirstnamelastname
idownertitlefile/content
Resource-orientedDesign
![Page 44: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/44.jpg)
5. Choose your content type(s)
Before we had CAD, we had Lead!, by Wendell
Resource-orientedDesign
![Page 45: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/45.jpg)
In conclusion...
Conclusion, by Mark Cummins
![Page 47: Grokking the REST Architectural Style](https://reader038.vdocument.in/reader038/viewer/2022102721/54b67db24a795962088b469a/html5/thumbnails/47.jpg)
Grokking the REST Architectural StyleCopyright © Ben Ramsey. Some rights reserved.
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.