ReST-ful Resource Management


Published on

This presentation was given on 11/30/2009 at the North Idaho .NET User Group meeting in Sandpoint, Idaho by Joe Davis.

Published in: Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

ReST-ful Resource Management

  1. 1. ReST-ful .NET Data Services Presented By: Joe Davis Twitter: @stygz Facebook:
  2. 2. HTTP Request Structure <ul><li>Method URI Protocol </li></ul><ul><li>Header1: Value1 </li></ul><ul><li>Header2: Value2 </li></ul><ul><li><empty line> </li></ul><ul><li>Body </li></ul>
  3. 3. HTTP GET Request <ul><li>GET HTTP/1.1 </li></ul><ul><li>Host: </li></ul><ul><li>User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) </li></ul>
  4. 4. HTTP POST Request <ul><li>POST HTTP/1.1 </li></ul><ul><li>Host: </li></ul><ul><li>User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) </li></ul><ul><li>myname=Joe+Davis </li></ul>
  5. 5. HTTP Response <ul><li>HTTP/1.1 200 OK </li></ul><ul><li>Content-Type: text/html </li></ul><ul><li>Content-length: 95 </li></ul><ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>Sample HTML Document</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li>Hello, Nurse! </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  6. 6. Quick Web Proxy Demo <ul><li>WebScarab </li></ul>
  7. 7. Semantics Structure (HTML) Presentation (Style) Behavior (Script) Perform Action Supply Context Specify Resource
  8. 8. The Web IS ReST <ul><li>URI = Uniform RESOURCE Identifier </li></ul><ul><li>The HTML document is a “Representation” of a resource in its current “State” </li></ul><ul><li>Resource representations can exist in any combination of any digital format (HTML, XML, JSON, RDF, RSS, ??) </li></ul>
  9. 9. Identify the Resource <ul><li><PROTOCOL>://<HOST><PATH>?<QUERYSTRING> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li><link rel=“alternate” type=“application/atom+xml” href=“” > </li></ul><ul><li> </li></ul><ul><li><link rel=“alternate” type=“application/json” href=“” > </li></ul>
  10. 10. HTTP Methods Deletes resource DELETE Create or Update resource (returns current state after update) PUT Create resource (returns current state after creation—handy if server-generated resource ID is required) POST Retrieve resource HEADERS ONLY HEAD Retrieve resource headers and body GET
  11. 11. ReST GET Request/Response <ul><li>GET HTTP/1.1 </li></ul><ul><li>HOST: </li></ul>HTTP/1.1 200 OK Content-Type: application/json Content-Length: 53 {“ProductID”:123,”Name”:”Super Widget”,”Price”:49.99}
  12. 12. ReST POST Request/Response <ul><li>POST HTTP/1.1 </li></ul><ul><li>HOST: </li></ul><ul><li>Content-Type: application/json </li></ul><ul><li>Content-Length: 53 </li></ul><ul><li>{”Name”:”Ultra Wigdet”,”Price”:59.99} </li></ul>HTTP/1.1 201 CREATED Content-Type: application/json Content-Length: 53 {“ProductID”:456,”Name”:”Ultra Wigdet”,”Price”:59.99}
  13. 13. ReST PUT Request/Response <ul><li>PUT HTTP/1.1 </li></ul><ul><li>HOST: </li></ul><ul><li>Content-Type: application/json </li></ul><ul><li>Content-Length: 53 </li></ul><ul><li>{“ProductID”:456,”Name”:”Ultra Widget”,”Price”:59.99} </li></ul>HTTP/1.1 202 ACCEPTED Content-Type: application/json Content-Length: 53 {“ProductID”:456,”Name”:”Ultra Widget”,”Price”:59.99}
  14. 14. HTTP Success Status Codes Partial Content 206 No Content 204 Accepted 202 Created 201 OK 200
  15. 15. HTTP Redirection Status Codes Found (Temporary Redirection) 302 Moved Permanently 301 Multiple Choices 300
  16. 16. HTTP Error Status Codes Request entity too large 413 Conflict 409 Request timeout 408 Method not allowed 405 Resource not found 404 Forbidden 403 Unsupported media type 415 Unauthorized 401 Bad Request 400
  17. 17. HTTP Server Error Status Codes HTTP version not supported 505 Service Unavailable 503 Not Implemented 501 Internal Server Error 500
  18. 18. Isn’t this SOAP? <ul><li>No. </li></ul>
  19. 19. SOAP vs. ReST <ul><li>GET HTTP/1.1 </li></ul><ul><li>HOST: </li></ul>POST HTTP/1.1 HOST: Content-Type: application/soap+xml Content-Length: 308 <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=“” soap:encodingStyle=&quot;;> <soap:Body xmlns:m=&quot;;>   <m:GetStock>     <m:StockName>MSFT</m:StockName>   </m:GetStock> </soap:Body> </soap:Envelope>
  20. 20. So what’s RDF? <ul><li>Resource Description Framework </li></ul><ul><li>Doesn’t require fore-knowledge of type </li></ul><ul><li>Applies common ontology </li></ul><ul><li>High discoverability </li></ul><ul><li>Great framework. Terrible metaphor. </li></ul><ul><ul><li>Subject/Predicate/Object ?? </li></ul></ul><ul><ul><li>Entity/Attribute/Value !! </li></ul></ul><ul><li>.NET 4.0 supports tuples and dynamic types </li></ul>
  21. 21. Sample RDF Request/Response <ul><li>GET HTTP/1.1 </li></ul><ul><li>HOST: </li></ul>HTTP/1.1 200 OK Content-Type: text/rdf Content-Length: 389 <?xml version=&quot;1.0&quot;?> <rdf:RDF xmlns:rdf=&quot;; xmlns:product=&quot;;> <product:Widget rdf:about=&quot;;> <product:ProductID>123</product:ProductID> <product:Name>Super Widget</product:Name> <product:Price>49.99</product:Price> </product:Widget > </rdf:RDF>
  22. 22. More Info…. <ul><li>“ How I Explained ReST to my Wife” – Ryan Tomayko ( http:// /writings/rest-to-my-wife ) </li></ul><ul><li>ReSTful .NET: Build and Consume ReSTful Web Services with .NET 3.5 - Jon Flanders ( books&qid =1259709396&sr=8-1 ) </li></ul><ul><li>PluralSight Screencast – Aaron Skonnard ( ) </li></ul><ul><li>WebScarab Web Proxy Tool ( http:// ) </li></ul><ul><li>Fiddler Web Proxy Tool ( ) </li></ul><ul><li>WCF ReST Starter Kit ( =24644 ) </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.