Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to REST (OCPHP September 2009)

Ben Ramsey
September 24, 2009

Intro to REST (OCPHP September 2009)

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.

Ben Ramsey

September 24, 2009
Tweet

More Decks by Ben Ramsey

Other Decks in Programming

Transcript

  1. 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.
  2. used to interface, by Tom Hensel Uniform Interface 1.Identification of

    resources 2.Representation of resources 3.Linked resources 4.Resource metadata
  3. 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
  4. 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
  5. 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
  6. HTTP Interface #110 Hypertext Transfer Protocol, by maako Methods GET

    PUT POST DELETE Cut & Paste Copy Paste Over Paste After Cut
  7. 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
  8. GET / HTTP/1.1 Host: atom.example.org HTTP/1.x 200 OK Date: Mon,

    21 Sep 2009 16:33:45 GMT Content-Type: application/atomsvc+xml
  9. <?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>
  10. GET /user HTTP/1.1 Host: atom.example.org HTTP/1.x 200 OK Date: Mon,

    21 Sep 2009 16:34:26 GMT Content-Type: application/atom+xml
  11. <?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>
  12. GET /user/ramsey HTTP/1.1 Host: atom.example.org HTTP/1.x 200 OK Date: Mon,

    21 Sep 2009 16:34:26 GMT Content-Type: application/atom+xml;type=entry
  13. <?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"/> <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"> <a class="fn">Ben Ramsey</a> <span class="tel">123-456-7890</span> </div> </content> </entry>
  14. <?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"/> <id>tag:example.org,2008:user/ramsey</id> <updated>2009-09-22T09:14:58Z</updated> <published>2008-05-23T16:23:34Z</published> <content type="xhtml"> <div class="vcard"> <a class="fn url" href="http://benramsey.com/">Ben Ramsey</a> <span class="org">Schematic</span> <span class="tel">123-456-7890</span> </div> </content> </entry>
  15. PUT /user/ramsey HTTP/1.1 Host: atom.example.org Content-Type: application/atom+xml;type=entry {body here} HTTP/1.x

    200 OK Date: Mon, 22 Sep 2009 09:14:59 GMT Content-Type: application/atom+xml;type=entry
  16. <?xml version="1.0" encoding="utf-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xml:base="http://atom.example.org/"> <title>Perfect</title> <author> <name>Mark Phelps</name>

    </author> <id>tag:example.org,2009:content/perfect</id> <published>2009-09-22T20:12:08Z</published> <content type="application/mp4"> TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWF IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGl ... </content> </entry>
  17. POST /content HTTP/1.1 Host: atom.example.org Content-Type: application/atom+xml;type=entry {body here} HTTP/1.x

    202 Accepted Date: Mon, 22 Sep 2009 09:14:59 GMT {body contains status indicator}
  18. Intro to REST Copyright © 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.