Intro to REST (OCPHP September 2009)

0c217b9a7dd0aa31ed40bd0f453727e1?s=47 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.

0c217b9a7dd0aa31ed40bd0f453727e1?s=128

Ben Ramsey

September 24, 2009
Tweet

Transcript

  1. Ben Ramsey ▪ OCPHP/LAPHP Meeting ▪ 24 Sep 2009 Intro

    to REST
  2. REST Roatan Beach - Perfect Day, by Janusz Leszczynski

  3. Tom Coates, by Patrick Lauke Is it about pretty URLs?

  4. Web Developer Gang Sign, by Josh Lewis How about XML

    over HTTP? #webdevgangsign
  5. A Bar of Ivory Soap, by iirraa Any web service

    that’s not SOAP?
  6. Representational State Transfer Restful Summer, by Clear Inner Vision

  7. 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.
  8. Client-server Separated, by Hansol Lee

  9. Stateless Stateless by Koesmanto Bong

  10. Cache Cache County, Utah by J. Stephen Conn

  11. used to interface, by Tom Hensel Uniform Interface 1.Identification of

    resources 2.Representation of resources 3.Linked resources 4.Resource metadata
  12. Layered Sedimentary Layers by Mark Thurman

  13. Code-on-demand jeremy’s tie by Gitchel

  14. 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
  15. 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
  16. 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
  17. HTTP Interface #110 Hypertext Transfer Protocol, by maako Methods GET

    PUT POST DELETE Cut & Paste Copy Paste Over Paste After Cut
  18. 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
  19. Let’s see it in action

  20. 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
  21. <?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>
  22. 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
  23. <?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>
  24. Manipulate a user

  25. 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
  26. <?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>
  27. <?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>
  28. 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
  29. Add some content

  30. <?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>
  31. 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}
  32. Questions? benramsey.com

  33. 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.