rest1-111104225901-phpapp01
TRANSCRIPT
-
8/12/2019 rest1-111104225901-phpapp01
1/19
REST
Representational State Transfer
-
8/12/2019 rest1-111104225901-phpapp01
2/19
whoami
Colin Harrington [email protected] [email protected]
http://colinharrington.net@ColinHarrington
http://twitter.com/#%21/ColinHarringtonhttp://twitter.com/#%21/ColinHarringtonhttp://colinharrington.net/mailto:[email protected]:[email protected] -
8/12/2019 rest1-111104225901-phpapp01
3/19
History
HTTP:: HyperText Transfer ProtocolTim Berners-Lee:: 1990sFoundations of theWeb
OSILayer 7Application Layer
Protocol
http://en.wikipedia.org/wiki/OSI_model#Layer_7:_application_layerhttp://en.wikipedia.org/wiki/OSI_model#Layer_7:_application_layerhttp://en.wikipedia.org/wiki/OSI_modelhttp://www.w3.org/Protocols/HTTP/AsImplemented.htmlhttp://www.w3.org/People/Berners-Lee/http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol -
8/12/2019 rest1-111104225901-phpapp01
4/19
History
REST:: 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 Americancomputer
scientist[1], one of the principal authors of the HTTPspecification, an
authority on computer networkarchitecture[2]and co-founder of the
Apache HTTP Server
project."(Wikipedia)
http://roy.gbiv.com/@fielding
http://roy.gbiv.com/http://roy.gbiv.com/http://roy.gbiv.com/http://en.wikipedia.org/wiki/Apache_HTTP_Serverhttp://en.wikipedia.org/wiki/Computer_networkhttp://en.wikipedia.org/wiki/Roy_Fielding#cite_note-1http://en.wikipedia.org/wiki/Roy_Fielding#cite_note-0http://en.wikipedia.org/wiki/HTTPhttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htmhttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htmhttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htmhttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htmhttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htmhttp://en.wikipedia.org/wiki/Roy_Fieldinghttp://en.wikipedia.org/wiki/Roy_Fieldinghttp://en.wikipedia.org/wiki/Roy_Fieldinghttp://en.wikipedia.org/wiki/Representational_state_transferhttp://twitter.com/#%21/fieldinghttp://roy.gbiv.com/http://en.wikipedia.org/wiki/Roy_Fieldinghttp://en.wikipedia.org/wiki/Apache_HTTP_Serverhttp://en.wikipedia.org/wiki/Roy_Fielding#cite_note-1http://en.wikipedia.org/wiki/Computer_networkhttp://en.wikipedia.org/wiki/HTTPhttp://en.wikipedia.org/wiki/Roy_Fielding#cite_note-0http://en.wikipedia.org/wiki/United_States_of_Americahttp://www.ics.uci.edu/~fielding/pubs/dissertation/top.htmhttp://en.wikipedia.org/wiki/Roy_Fieldinghttp://en.wikipedia.org/wiki/Representational_state_transfer -
8/12/2019 rest1-111104225901-phpapp01
5/19
History - REST
Architecture:Client-Server Stateless + CacheableUniform Interface + Layerable
Data:Resources, identifiers & metadataRepresentation & metadataControl Data { headers }
Elements: {clients, server, resolver, cache}Gateways, proxies, user agentsURL, URI, Schemes
-
8/12/2019 rest1-111104225901-phpapp01
6/19
REST
REST is a buzzword and a movement but it symbolizes a coherentusage of the web (HTTP) as it was designed
REST ~ HTTP done right.
-
8/12/2019 rest1-111104225901-phpapp01
7/19
Resources
Uniform Resource Identifiers (URI)
:
ftp://example.org/resource.txt urn:issn:1535-3613
mailto:[email protected]
Uniform Resource Locator(URL)
scheme://domain:port/path?query_string
-
8/12/2019 rest1-111104225901-phpapp01
8/19
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.com
Accept: */*
http://www.google.com/ -
8/12/2019 rest1-111104225901-phpapp01
9/19
Accept Headers :: Client
GET / HTTP/1.1User-Agent: curl/7.21.0Host: www.google.com
Accept: */*
Accept: application/xml
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json
-
8/12/2019 rest1-111104225901-phpapp01
10/19
HTTP Status Codes
200- OK301- Moved permanently302- Moved temporarily404- Not Found
500http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
HTTP/1.1 200 OK
Date: Mon, 31 Oct 2011 16:07:53 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html -
8/12/2019 rest1-111104225901-phpapp01
11/19http://homestarrunner.com/404d
http://homestarrunner.com/404d -
8/12/2019 rest1-111104225901-phpapp01
12/19
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" } ]}
http://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_examplehttp://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_examplehttp://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_examplehttp://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_examplehttp://www.w3.org/RDF/http://en.wikipedia.org/wiki/XHTMLhttp://en.wikipedia.org/wiki/HTMLhttp://en.wikipedia.org/wiki/JSONhttp://www.w3schools.com/xml/xml_whatis.asp -
8/12/2019 rest1-111104225901-phpapp01
13/19
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
-
8/12/2019 rest1-111104225901-phpapp01
14/19
Cacheability
HTTP Cache Headers
Expires
Cache-Control
ETag Last-Modified
Pragma no-cacheProxy & Network path.
-
8/12/2019 rest1-111104225901-phpapp01
15/19
CRUD
Create :: POST
Read :: GET
Update :: PUT
Delete :: DELETE
* http://stackoverflow.com/questions/630453/put-vs-post-in-rest
http://stackoverflow.com/questions/630453/put-vs-post-in-rest -
8/12/2019 rest1-111104225901-phpapp01
16/19
Hypermedia
Linkingto other resources / media
HTML documents, resources
loosely coupledImages, CSS, favicon, etc.
Like this image ->http://cuip.uchicago.edu/~cac/images/Hypermedia.jpg
http://en.wikipedia.org/wiki/Hypermediahttp://en.wikipedia.org/wiki/Hypermedia -
8/12/2019 rest1-111104225901-phpapp01
17/19
Who
http://www.programmableweb.com/Amazon Web Services {S3, EC2, SQS, RDS, FPS, etc.}
Just to name a few...
http://www.programmableweb.com/ -
8/12/2019 rest1-111104225901-phpapp01
18/19
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 RESTfuland play around with it. I'recommend using http://www.twilio.com/just because they offer you$30 in free credit and you get to make, receive and control real phonecalls.
http://www.twilio.com/https://addons.mozilla.org/en-US/firefox/addon/poster/http://blogs.plexibus.com/2009/01/15/rest-esting-with-curl/http://tomayko.com/writings/rest-to-my-wifehttp://www.twilio.com/https://addons.mozilla.org/en-US/firefox/addon/poster/http://blogs.plexibus.com/2009/01/15/rest-esting-with-curl/http://tomayko.com/writings/rest-to-my-wife -
8/12/2019 rest1-111104225901-phpapp01
19/19
Thank You