Brief Introduction to REST

3,446 views

Published on

This is from a guest lecture that I delivered to a web-programming class at Bethel University in Arden Hills, MN

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,446
On SlideShare
0
From Embeds
0
Number of Embeds
223
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Brief Introduction to REST

  1. 1. RESTRepresentational State Transfer
  2. 2. whoamiColin Harrington ● colin.harrington@objectpartners.com ● colin@colinharrington.net ● http://colinharrington.net ● @ColinHarrington
  3. 3. HistoryHTTP :: HyperText Transfer ProtocolTim Berners-Lee :: 1990sFoundations of the WebOSI Layer 7Application LayerProtocol
  4. 4. HistoryREST :: Representational State Transfer2000 Doctoral Dissertation by Roy T. Fieldinghttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm"Roy Thomas Fielding (born 1965) is an American computerscientist[1], one of the principal authors of the HTTP specification, anauthority on computer network architecture[2] and co-founder of theApache HTTP Server project." (Wikipedia)http://roy.gbiv.com/@fielding
  5. 5. History - RESTArchitecture: ● Client-Server ● Stateless + Cacheable ● Uniform Interface + LayerableData: ● Resources, identifiers & metadata ● Representation & metadata ● Control Data { headers }Elements: ● {clients, server, resolver, cache} ● Gateways, proxies, user agents ● URL, URI, Schemes
  6. 6. RESTREST is a buzzword and a movement but it symbolizes a coherentusage of the web (HTTP) as it was designed REST ~ HTTP done right.
  7. 7. ResourcesUniform Resource Identifiers (URI) <scheme>:<scheme-specified-structure> ● ftp://example.org/resource.txt ● urn:issn:1535-3613 ● mailto:colin@colinharrington.netUniform Resource Locator (URL) scheme://domain:port/path?query_string
  8. 8. HTTP Methods/VerbsHEAD, GET, OPTIONS => considered "safe"PUT, POST, DELETE => possibly destructiveTRACE, DEBUG => Considered harmfulcurl -v http://www.google.comGET / HTTP/1.1User-Agent: curl/7.21.0Host: www.google.comAccept: */*
  9. 9. Accept Headers :: ClientGET / HTTP/1.1User-Agent: curl/7.21.0Host: www.google.comAccept: */*Accept: application/xmlAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json
  10. 10. HTTP Status Codes200 - OK301 - Moved permanently302 - Moved temporarily404 - Not Found500 http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.htmlHTTP/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
  11. 11. http://homestarrunner.com/404d
  12. 12. Representations JSON Example ● XML { "firstName": "John", "lastName" : "Smith", "age" : 25, ● JSON "address" : { "streetAddress": "21 2nd Street", "city" : "New York", ● HTML "state" : "NY", "postalCode" : "10021" }, "phoneNumber": ● XHTML [ { "type" : "home", "number": "212 555-1234" ● RDF }, { "type" : "fax", "number": "646 555-4567" ● Text ] } } ● Custom Formats
  13. 13. Content NegotiationRequest:Accept Header Accept: application/xmlAccept-LanguageAccept-EncodingResponse:Content-Type: text/jsonAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json
  14. 14. CacheabilityHTTP Cache Headers ● Expires ● Cache-Control ● ETag ● Last-Modified ● Pragma no-cacheProxy & Network path.
  15. 15. CRUD Create :: POST Read :: GET Update :: PUT Delete :: DELETE* http://stackoverflow.com/questions/630453/put-vs-post-in-rest
  16. 16. HypermediaLinking to other resources / mediaHTML documents, resourcesloosely coupledImages, CSS, favicon, etc.Like this image ->http://cuip.uchicago.edu/~cac/images/Hypermedia.jpg
  17. 17. Whohttp://www.programmableweb.com/Amazon Web Services {S3, EC2, SQS, RDS, FPS, etc.}Just to name a few...
  18. 18. ResourcesThis guy explains REST in to his non-technical wife:http://tomayko.com/writings/rest-to-my-wifeGood 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/Youd probably learn best by actually making some RESTfulcalls. Pick a service that is free and RESTful and play around with it. Idrecommend using http://www.twilio.com/ just because they offer you$30 in free credit and you get to make, receive and control real phonecalls.
  19. 19. Thank You

×