View
2.869
Download
2
Category
Preview:
DESCRIPTION
This is from a guest lecture that I delivered to a web-programming class at Bethel University in Arden Hills, MN
Citation preview
REST
Representational State Transfer
whoami
Colin Harrington● colin.harrington@objectpartners.com● colin@colinharrington.net ● http://colinharrington.net ●@ColinHarrington
History
HTTP :: HyperText Transfer ProtocolTim Berners-Lee :: 1990s Foundations of the Web OSI Layer 7 Application Layer Protocol
History
REST :: Representational State Transfer 2000 Doctoral Dissertation by Roy T. Fielding http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm "Roy Thomas Fielding (born 1965) is an American computer scientist[1], one of the principal authors of the HTTP specification, an authority on computer network architecture[2] and co-founder of the Apache HTTP Server project." (Wikipedia)
http://roy.gbiv.com/ @fielding
History - REST
Architecture: ●Client-Server● Stateless + Cacheable●Uniform Interface + Layerable
Data: ●Resources, identifiers & metadata●Representation & metadata●Control Data { headers }
Elements:● {clients, server, resolver, cache}●Gateways, proxies, user agents●URL, URI, Schemes
REST
REST is a buzzword and a movement but it symbolizes a coherent usage of the web (HTTP) as it was designed
REST ~ HTTP done right.
Resources
Uniform Resource Identifiers (URI)
<scheme>:<scheme-specified-structure>
● ftp://example.org/resource.txt● urn:issn:1535-3613● mailto:colin@colinharrington.net
Uniform Resource Locator (URL)
scheme://domain:port/path?query_string
HTTP Methods/Verbs
HEAD, GET, OPTIONS => considered "safe" PUT, POST, DELETE => possibly destructiveTRACE, DEBUG => Considered harmful
curl -v http://www.google.com
GET / HTTP/1.1User-Agent: curl/7.21.0Host: www.google.comAccept: */*
Accept Headers :: Client
GET / HTTP/1.1User-Agent: curl/7.21.0Host: www.google.comAccept: */* Accept: application/xml Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json
HTTP Status Codes
200 - OK301 - Moved permanently302 - Moved temporarily 404 - Not Found500
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
HTTP/1.1 200 OKDate: Mon, 31 Oct 2011 16:07:53 GMTExpires: -1Cache-Control: private, max-age=0Content-Type: text/html; charset=ISO-8859-1
Representations
●XML
● JSON
●HTML
●XHTML
●RDF
● Text
●Custom Formats
JSON Example { "firstName": "John", "lastName" : "Smith", "age" : 25, "address" : { "streetAddress": "21 2nd Street", "city" : "New York", "state" : "NY", "postalCode" : "10021" }, "phoneNumber": [ { "type" : "home", "number": "212 555-1234" }, { "type" : "fax", "number": "646 555-4567" } ] }
Content Negotiation
Request: Accept Header Accept: application/xml
Accept-LanguageAccept-Encoding Response: Content-Type: text/json Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json
Cacheability
HTTP Cache Headers
● Expires● Cache-Control ● ETag● Last-Modified● Pragma no-cache
Proxy & Network path.
CRUD
Create :: POST
Read :: GET
Update :: PUT
Delete :: DELETE
* http://stackoverflow.com/questions/630453/put-vs-post-in-rest
Hypermedia
Linking to other resources / media
HTML documents, resourcesloosely coupled Images, CSS, favicon, etc.
Like this image -> http://cuip.uchicago.edu/~cac/images/Hypermedia.jpg
Who
http://www.programmableweb.com/ Amazon Web Services {S3, EC2, SQS, RDS, FPS, etc.}
Just to name a few...
Resources
This guy explains REST in to his non-technical wife:http://tomayko.com/writings/rest-to-my-wife
Good article on how to REST with curl: http://blogs.plexibus.com/2009/01/15/rest-esting-with-curl/
Poster -- the Firefox plugin:https://addons.mozilla.org/en-US/firefox/addon/poster/
You'd probably learn best by actually making some RESTful calls. Pick a service that is free and RESTful and play around with it. I'd recommend using http://www.twilio.com/ just because they offer you $30 in free credit and you get to make, receive and control real phone calls.
Thank You
Recommended