Slide 1

Slide 1 text

Monetizing Social Ben Ramsey • Nashville PHP User Group • 8 Mar 2011 Grokking REST

Slide 2

Slide 2 text

What is REST?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

#webdevgangsign

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Representational State Transfer

Slide 7

Slide 7 text

Client-server

Slide 8

Slide 8 text

Stateless

Slide 9

Slide 9 text

Cache

Slide 10

Slide 10 text

Uniform Interface

Slide 11

Slide 11 text

Layered System

Slide 12

Slide 12 text

Code-on-demand

Slide 13

Slide 13 text

RESTful Concepts

Slide 14

Slide 14 text

Resources & URLs

Slide 15

Slide 15 text

URLs do not matter

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Using URLs as interfaces creates tight coupling between the client & server

Slide 18

Slide 18 text

http://api.example.org/user/getUser?u=ramsey

Slide 19

Slide 19 text

Using URL templates creates tight coupling between the client & server

Slide 20

Slide 20 text

http://api.example.org/user/{username}/photos

Slide 21

Slide 21 text

Your hypermedia format should expose the URLs that represent your resources

Slide 22

Slide 22 text

ramsey ramsey tag:example.org,2008:user/ramsey 2009-09-21T13:45:00Z 2008-05-23T16:23:34Z
Ben Ramsey 123-456-7890

Slide 23

Slide 23 text

Hypermedia

Slide 24

Slide 24 text

application/json

Slide 25

Slide 25 text

{ "id": "756315701", "name": "Ben Ramsey", "first_name": "Ben", "last_name": "Ramsey", "link": "http://www.facebook.com/ramseyben", "gender": "male", "locale": "en_US" }

Slide 26

Slide 26 text

Hypermedia?

Slide 27

Slide 27 text

No.

Slide 28

Slide 28 text

application/facebook+json; type=user

Slide 29

Slide 29 text

application/xml

Slide 30

Slide 30 text

756315701 Ben Ramsey Ben Ramsey http://www.facebook.com/ramseyben male en_US

Slide 31

Slide 31 text

Hypermedia?

Slide 32

Slide 32 text

No.

Slide 33

Slide 33 text

application/facebook+xml; type=user

Slide 34

Slide 34 text

application/xhtml+xml

Slide 35

Slide 35 text

Hypermedia?

Slide 36

Slide 36 text

Yes!

Slide 37

Slide 37 text

application/atom+xml

Slide 38

Slide 38 text

Hypermedia?

Slide 39

Slide 39 text

Yes!

Slide 40

Slide 40 text

HATEOAS

Slide 41

Slide 41 text

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

Slide 42

Slide 42 text

Grokking REST • Ben Ramsey HATEOAS ‣Hypermedia as the engine of application state ‣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

Slide 43

Slide 43 text

Why is REST so great?

Slide 44

Slide 44 text

REST scales

Slide 45

Slide 45 text

It’s extensible

Slide 46

Slide 46 text

It’s evolvable

Slide 47

Slide 47 text

Grokking REST • Ben Ramsey Accept: application/vnd.myservice+xml;version=2 Use this style for versioning 47

Slide 48

Slide 48 text

Grokking REST • Ben Ramsey http://api.example.org/v2/foo Not this style 48

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

It’s seamless

Slide 51

Slide 51 text

Atom

Slide 52

Slide 52 text

Entry Document application/atom+xml;type=entry Feed/Collection Document application/atom+xml Category Document application/atomcat+xml Service Document application/atomsvc+xml

Slide 53

Slide 53 text

GET  /  HTTP/1.1   Host:  atom.example.org   Accept:  application/atomsvc+xml,  application/atomcat+xml,  application/atom+xml HTTP/1.x  200  OK   Date:  Mon,  21  Sep  2009  16:33:45  GMT   Content-­‐Type:  application/atomsvc+xml              Our  Content  Store              Users        application/atom+xml;type=entry                            Content        application/atom+xml;type=entry                    

Slide 54

Slide 54 text

GET  /user  HTTP/1.1   Host:  atom.example.org   Accept:  application/atom+xml HTTP/1.x  200  OK   Date:  Mon,  21  Sep  2009  16:34:26  GMT   Content-­‐Type:  application/atom+xml        Users    2009-­‐09-­‐21T05:21:19Z    tag:example.org,2009-­‐09:user          Users      application/atom+xml;type=entry                                ...      

Slide 55

Slide 55 text

GET  /cat/user  HTTP/1.1   Host:  atom.example.org   Accept:  application/atomcat+xml HTTP/1.x  200  OK   Date:  Mon,  22  Sep  2009  09:39:26  GMT   Content-­‐Type:  application/atomcat+xml                  

Slide 56

Slide 56 text

POST  /user  HTTP/1.1   Host:  atom.example.org   Content-­‐Type:  application/atom+xml;type=entry        ramsey          ramsey        tag:example.org,2008:user/ramsey    2008-­‐05-­‐23T16:23:34Z            
         Ben  Ramsey          123-­‐456-­‐7890        
      HTTP/1.x  201  Created   Date:  Mon,  22  Sep  2009  09:39:26  GMT   Location:  http://atom.example.org/user/ramsey   Content-­‐Type:  text/html          

Your  new  resource  was  created            here.

   

Slide 57

Slide 57 text

Bringing it all together…

Slide 58

Slide 58 text

Grokking REST • Ben Ramsey Questions? ‣I blog at benramsey.com. ‣I tweet at @ramsey. ‣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

Slide 59

Slide 59 text

Grokking REST Copyright © 2011 Ben Ramsey. Some rights reserved. Presented on March 8, 2011 at Nashville PHP User Group, CoLab, Nashville, TN. 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.

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

Grokking REST • Ben Ramsey Photo Credits ‣Molecule display, by Christian Guthier ‣Conclusion, by Mark Cummins 61