brief introduction to rest

19
REST Representational State Transfer

Upload: colin-harrington

Post on 09-May-2015

2.866 views

Category:

Technology


2 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Brief Introduction to REST

REST

Representational State Transfer

Page 4: Brief Introduction to REST

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

Page 5: Brief Introduction to REST

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

Page 6: Brief Introduction to REST

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.

Page 7: Brief Introduction to REST

Resources

Uniform Resource Identifiers (URI)

<scheme>:<scheme-specified-structure>

● ftp://example.org/resource.txt● urn:issn:1535-3613● mailto:[email protected]

Uniform Resource Locator (URL)

scheme://domain:port/path?query_string

Page 8: Brief Introduction to REST

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: */*

Page 9: Brief Introduction to REST

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

Page 10: Brief Introduction to REST

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

Page 11: Brief Introduction to REST

http://homestarrunner.com/404d

Page 12: Brief Introduction to REST

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" } ] }

Page 13: Brief Introduction to REST

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

Page 14: Brief Introduction to REST

Cacheability

HTTP Cache Headers

● Expires● Cache-Control ● ETag● Last-Modified● Pragma no-cache

Proxy & Network path.

Page 15: Brief Introduction to REST

CRUD

Create :: POST

Read :: GET

Update :: PUT

Delete :: DELETE

* http://stackoverflow.com/questions/630453/put-vs-post-in-rest

Page 16: Brief Introduction to 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

Page 17: Brief Introduction to REST

Who

http://www.programmableweb.com/ Amazon Web Services {S3, EC2, SQS, RDS, FPS, etc.}

Just to name a few...

Page 18: Brief Introduction to REST

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.

Page 19: Brief Introduction to REST

Thank You