REST in peace @ Osidays 2011 India 11-21-2011

2,274 views
2,151 views

Published on

Presentation given at OSIDays 2011 in Bangalore, dealing wiith understanding the 5 main principles of REST and how to produce scalable and durable web architectures.

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

No Downloads
Views
Total views
2,274
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
11
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

REST in peace @ Osidays 2011 India 11-21-2011

  1. 1. RESTin peaceBengaluru, 20-22 November 2011
  2. 2. Sorry for the ugly slide. There will be others. Really sorry. Bengaluru, 20-22 November 2011
  3. 3. REST in a nutshell Bengaluru, 20-22 November 2011
  4. 4. 2000 Fieldings dissertation: REpresentational State Transferhttp://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm Bengaluru, 20-22 November 2011
  5. 5. REST in a nutshell:1. Client <> Server Bengaluru, 20-22 November 2011
  6. 6. REST in a nutshell: 2. Stateless Bengaluru, 20-22 November 2011
  7. 7. Servers do not keep anyinformations the clients uses during different requests. Bengaluru, 20-22 November 2011
  8. 8. So the architecture scales well. Bengaluru, 20-22 November 2011
  9. 9. REST in a nutshell: 3. Cacheable Bengaluru, 20-22 November 2011
  10. 10. Client has access toresources stored between it and the origin server. Bengaluru, 20-22 November 2011
  11. 11. So communication is faster. Bengaluru, 20-22 November 2011
  12. 12. REST in a nutshell:4. Layered system Bengaluru, 20-22 November 2011
  13. 13. Intermediary nodes can beused along our architecture. Bengaluru, 20-22 November 2011
  14. 14. So you efficiently implement point 3. Bengaluru, 20-22 November 2011
  15. 15. REST in a nutshell: 5. Uniform interface Bengaluru, 20-22 November 2011
  16. 16. Communicate using well-known verbs and providing all the informations needed to consume a service. Bengaluru, 20-22 November 2011
  17. 17. So fallbacks are easy. Bengaluru, 20-22 November 2011
  18. 18. this was a bit difficult to understand so, obviously... Bengaluru, 20-22 November 2011
  19. 19. nobody had a clue Bengaluru, 20-22 November 2011
  20. 20. ANTIPATTERNS Bengaluru, 20-22 November 2011
  21. 21. 1 URIsBengaluru, 20-22 November 2011
  22. 22. "REST is about cool URI design"http://apple.com/users/1/licenses/4.json Bengaluru, 20-22 November 2011
  23. 23. "REST is about cool URI design"http://apple.com/users/1/licenses/4.json Bengaluru, 20-22 November 2011
  24. 24. http://apple.com/site/en_US/showUsers.jsp?uid=1&license=4 is OK too Bengaluru, 20-22 November 2011
  25. 25. but, enter simple rule of thumb Bengaluru, 20-22 November 2011
  26. 26. cool URIs help youthink in term of resources - David Zuelke Bengaluru, 20-22 November 2011
  27. 27. 2 URIs (bis)Bengaluru, 20-22 November 2011
  28. 28. REST follows a URI schema GET /users POST /users PUT /users/{id} DELETE /users/{id} ... Bengaluru, 20-22 November 2011
  29. 29. REST follows a URI schema GET /users POST /users PUT /users/{id} DELETE /users/{id} ... Bengaluru, 20-22 November 2011
  30. 30. what if you change your URL? Bengaluru, 20-22 November 2011
  31. 31. client isbroken Bengaluru, 20-22 November 2011
  32. 32. RESTful clients should be driven by services hypermedia controlsRoy Fielding : http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven Bengaluru, 20-22 November 2011
  33. 33. HATEOAS Bengaluru, 20-22 November 2011
  34. 34. 3POST is coolBengaluru, 20-22 November 2011
  35. 35. said SOAP 1.1 Bengaluru, 20-22 November 2011
  36. 36. said SOAP 1.1 Bengaluru, 20-22 November 2011
  37. 37. loosing meaningful verbs at the protocol level Bengaluru, 20-22 November 2011
  38. 38. loosing meaningful verbs at the protocol level nothing cacheable by default Bengaluru, 20-22 November 2011
  39. 39. loosing meaningful verbs at the protocol level nothing cacheable by default what about bookmarking? Bengaluru, 20-22 November 2011
  40. 40. 4500 is your friend Bengaluru, 20-22 November 2011
  41. 41. said SOAP ( again ) Bengaluru, 20-22 November 2011
  42. 42. GET /users/300Host: www.example.comBengaluru, 20-22 November 2011
  43. 43. GET /users/300 Host: www.example.comHTTP/1.1 500 Internal Server ErrorEtag: 1234X-Powered-By: php/5.3...The record cannot be found Bengaluru, 20-22 November 2011
  44. 44. GET /users/300 Host: www.example.comHTTP/1.1 500 Internal Server ErrorEtag: 1234X-Powered-By: php/5.3...The record cannot be found Bengaluru, 20-22 November 2011
  45. 45. The HTTP protocol is awesome,and lets you return meaningful anduniversally-understood status codes Bengaluru, 20-22 November 2011
  46. 46. 404 Not FoundBengaluru, 20-22 November 2011
  47. 47. 404 Not Found OMG Link is broken?Bengaluru, 20-22 November 2011
  48. 48. 202 AcceptedBengaluru, 20-22 November 2011
  49. 49. 202 AcceptedYou get an immediate OK, and the operation will hopefully complete Bengaluru, 20-22 November 2011
  50. 50. PauseBengaluru, 20-22 November 2011
  51. 51. The WWW Bengaluru, 20-22 November 2011
  52. 52. the largest data-exchange network on the planet Bengaluru, 20-22 November 2011
  53. 53. And meanwhile, at Facebook...12TB of new data every day (1 year ago) 500 million users Bengaluru, 20-22 November 2011
  54. 54. And meanwhile, at Google... 1 billionunique monthly googlers Bengaluru, 20-22 November 2011
  55. 55. via HTTP , baby! Bengaluru, 20-22 November 2011
  56. 56. HTTP in a nutshell:1. Client <> Server Bengaluru, 20-22 November 2011
  57. 57. HTTP in a nutshell: 2. Stateless Bengaluru, 20-22 November 2011
  58. 58. HTTP in a nutshell:3. widespread cache spec http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html Bengaluru, 20-22 November 2011
  59. 59. HTTP in a nutshell: Lao Tze Song using Firefox 6 Company proxy Great chinese (fire)wall Reverse proxy Origin server4. Layered system Bengaluru, 20-22 November 2011
  60. 60. HTTP in a nutshell: 5. it is the uniform interface between clients and servers Bengaluru, 20-22 November 2011
  61. 61. HTTP bleeds REST Bengaluru, 20-22 November 2011
  62. 62. How do Iimplement thisgoodness? Bengaluru, 20-22 November 2011
  63. 63. 1.caching & scalability Bengaluru, 20-22 November 2011
  64. 64. HTTP cache Bengaluru, 20-22 November 2011
  65. 65. Types of cache Local Shared/proxy Shared/reverse proxy Bengaluru, 20-22 November 2011
  66. 66. Types of cache Local Shared/proxy Shared/reverse proxy Bengaluru, 20-22 November 2011
  67. 67. Bengaluru, 20-22 November 2011
  68. 68. Types of cache Local Shared/proxy Shared/reverse proxy Bengaluru, 20-22 November 2011
  69. 69. Bengaluru, 20-22 November 2011
  70. 70. Types of cache Local Shared/proxyShared/reverse proxy Bengaluru, 20-22 November 2011
  71. 71. Bengaluru, 20-22 November 2011
  72. 72. on the server sideBengaluru, 20-22 November 2011
  73. 73. Caching with Expiration (example) Bengaluru, 20-22 November 2011
  74. 74. HTTP/1.1 200 OKHost: www.example.comExpires: 0 Bengaluru, 20-22 November 2011
  75. 75. HTTP/1.1 200 OKHost: www.example.comExpires: 0 Bengaluru, 20-22 November 2011
  76. 76. HTTP/1.1 200 OKHost: www.example.comExpires: Tue, 31 Jan 2011 01:00 GMT Bengaluru, 20-22 November 2011
  77. 77. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public Bengaluru, 20-22 November 2011
  78. 78. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public Bengaluru, 20-22 November 2011
  79. 79. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public Cacheable for 60 seconds Bengaluru, 20-22 November 2011
  80. 80. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, publicCacheable by both local and shared caches Bengaluru, 20-22 November 2011
  81. 81. You can also cache with validation(Etags, If-None-Match, ...) Bengaluru, 20-22 November 2011
  82. 82. Why HTTP caching is so important? Bengaluru, 20-22 November 2011
  83. 83. Ask yourself:as a developer, what do I want on my application? Bengaluru, 20-22 November 2011
  84. 84. Evolve Loose coupling Work lessBengaluru, 20-22 November 2011
  85. 85. EvolveBecause you want your platform to extensible Loose coupling Work less Bengaluru, 20-22 November 2011
  86. 86. EvolveBecause you want your platform to extensible Loose couplingBecause you want it to be easy to integrate with, evolve, plugand mantain Work less Bengaluru, 20-22 November 2011
  87. 87. EvolveBecause you want your platform to extensible Loose couplingBecause you want it to be easy to integrate with, evolve, plugand mantain Work lessBecause every LoC is bug-prone and our man-day is a hard-to-scale cost Bengaluru, 20-22 November 2011
  88. 88. enters our Hero #1Bengaluru, 20-22 November 2011
  89. 89. Bengaluru, 20-22 November 2011
  90. 90. Bengaluru, 20-22 November 2011
  91. 91. enters our Hero #2Bengaluru, 20-22 November 2011
  92. 92. Bengaluru, 20-22 November 2011
  93. 93. http://www.lullabot.com/articles/a-beginners-guide-to-caching-data Bengaluru, 20-22 November 2011
  94. 94. 2007Bengaluru, 20-22 November 2011
  95. 95. 2011?Bengaluru, 20-22 November 2011
  96. 96. it supportsHTTP caching! http://drupal.org/node/147310 Bengaluru, 20-22 November 2011
  97. 97. it supportsHTTP caching! http://drupal.org/node/147310 ( people is supposed to clap their hands here ) Bengaluru, 20-22 November 2011
  98. 98. butBengaluru, 20-22 November 2011
  99. 99. wait.... how? Bengaluru, 20-22 November 2011
  100. 100. Default headersExpires = Sun, 19 Nov 1978 05:00:00 GMT,Cache-Control = no-cache, must-revalidate,ETag = $_SERVER[REQUEST_TIME], Bengaluru, 20-22 November 2011
  101. 101. Default headersExpires = Sun, 19 Nov 1978 05:00:00 GMT,Cache-Control = no-cache, must-revalidate,ETag = $_SERVER[REQUEST_TIME], Bengaluru, 20-22 November 2011
  102. 102. Default headersExpires = Sun, 19 Nov 1978 05:00:00 GMT,Cache-Control = no-cache, must-revalidate,ETag = $_SERVER[REQUEST_TIME], Bengaluru, 20-22 November 2011
  103. 103. Default headersExpires = Sun, 19 Nov 1978 05:00:00 GMT,Cache-Control = no-cache, must-revalidate,ETag = $_SERVER[REQUEST_TIME], Bengaluru, 20-22 November 2011
  104. 104. is that even legal?Bengaluru, 20-22 November 2011
  105. 105. "but you can redefine them!" Bengaluru, 20-22 November 2011
  106. 106. drupal_add_http_header() Bengaluru, 20-22 November 2011
  107. 107. function drupal_add_http_header(){ ... ... drupal_send_headers($headers);} Bengaluru, 20-22 November 2011
  108. 108. so, whatdrupal_send_headers() can do so evil? Bengaluru, 20-22 November 2011
  109. 109. header() , of course Bengaluru, 20-22 November 2011
  110. 110. which meansBengaluru, 20-22 November 2011
  111. 111. drupal_add_http_header(Dumb-Header, Im batman!);...// other logic...drupal_add_http_header(Dumb-Header, Im not);var_dump(headers_list()); Bengaluru, 20-22 November 2011
  112. 112. drupal_add_http_header(Dumb-Header, Im batman!);...// other logic...drupal_add_http_header(Dumb-Header, Im not);var_dump(headers_list());array 0 => string X-Powered-By: PHP/5.3.2-1ubuntu4.7 1 => string Dump-Header: Im not Bengaluru, 20-22 November 2011
  113. 113. drupal_add_http_header(Dumb-Header, Im batman!);...// other logic...drupal_add_http_header(Dumb-Header, false);var_dump(headers_list()); Bengaluru, 20-22 November 2011
  114. 114. drupal_add_http_header(Dumb-Header, Im batman!);...// other logic...drupal_add_http_header(Dumb-Header, false);var_dump(headers_list());array 0 => string X-Powered-By: PHP/5.3.2-1ubuntu4.7 1 => string Dump-Header: Im batman Bengaluru, 20-22 November 2011
  115. 115. drupal_add_http_header(Dumb-Header, Im batman!);...// other logic...drupal_add_http_header(Dumb-Header, );var_dump(headers_list()); Bengaluru, 20-22 November 2011
  116. 116. drupal_add_http_header(Dumb-Header, Im batman!);...// other logic...drupal_add_http_header(Dumb-Header, );var_dump(headers_list());array 0 => string X-Powered-By: PHP/5.3.2-1ubuntu4.7 1 => string Dumb-Header: Bengaluru, 20-22 November 2011
  117. 117. orBengaluru, 20-22 November 2011
  118. 118. you can use header_remove() ( PHP 5.3 ) Bengaluru, 20-22 November 2011
  119. 119. and create a new class to manage/keep track ofheaders and caching directives Bengaluru, 20-22 November 2011
  120. 120. but were lazy andwe dont want to reinvent the wheel Bengaluru, 20-22 November 2011
  121. 121. GoalsWork less evolve loose coupling Bengaluru, 20-22 November 2011
  122. 122. GoalsWork less evolve loose coupling Bengaluru, 20-22 November 2011
  123. 123. everything is done for us! :) but.... Bengaluru, 20-22 November 2011
  124. 124. tmp files, cache tables, procedural code... mmmmh.... gotta be something better Bengaluru, 20-22 November 2011
  125. 125. FrameworksBengaluru, 20-22 November 2011
  126. 126. Bengaluru, 20-22 November 2011
  127. 127. ONEBengaluru, 20-22 November 2011
  128. 128. Cache is used for compiling routes, autoloading, ... Bengaluru, 20-22 November 2011
  129. 129. Cache is used for compiling routes, autoloading, ... ...but also for storing the view Bengaluru, 20-22 November 2011
  130. 130. GoalsWork less evolve loose coupling Bengaluru, 20-22 November 2011
  131. 131. GoalsWork less evolve loose coupling Bengaluru, 20-22 November 2011
  132. 132. at least because we use a framework Bengaluru, 20-22 November 2011
  133. 133. HTTP
  134. 134. Less workBengaluru, 20-22 November 2011
  135. 135. http://www.flickr.com/photos/snakphotography/5004775320/sizes/o/in/photostream/ because the hard work is delegated to the browser/proxy Bengaluru, 20-22 November 2011
  136. 136. EvolveBengaluru, 20-22 November 2011
  137. 137. because cache is abstracted from the application Bengaluru, 20-22 November 2011
  138. 138. Loose coupling Bengaluru, 20-22 November 2011
  139. 139. because caching is bound to the protocol, HTTP, notto your implementation ( Sf, RoR, Django ) Bengaluru, 20-22 November 2011
  140. 140. but hey, you sayBengaluru, 20-22 November 2011
  141. 141. HTTPs cache fails when dealing with really dynamicpages, because consumers will always have to hit the origin server, although a part of the page would be cacheable ( header and footer, for example ) Bengaluru, 20-22 November 2011
  142. 142. Nope NopeBengaluru, 20-22 November 2011
  143. 143. ESI was built for that http://www.w3.org/TR/esi-lang Bengaluru, 20-22 November 2011
  144. 144. Edge Side Includes A de facto standard for bla bla bla... Bengaluru, 20-22 November 2011
  145. 145. Edge Side Includes A de facto standard for bla bla bla... Server side includes ( not SSI! ) usually handled by the architectures ESI processor. http://www.w3.org/TR/esi-lang http://www.w3.org/TR/edge-arch
  146. 146. <esi:include src="http://osidays.com/talks/1" /> Bengaluru, 20-22 November 2011
  147. 147. <esi:include src="http://osidays.com/talks/1" /> Bengaluru, 20-22 November 2011
  148. 148. <esi:include src="http://osidays.com/talks/1" /> Bengaluru, 20-22 November 2011
  149. 149. 1s (tweets)3600 (post) Bengaluru, 20-22 November 2011
  150. 150. <esi:include src=tweets.html /><esi:include src=article/12.html /> Bengaluru, 20-22 November 2011
  151. 151. 2.adaptability & durability Bengaluru, 20-22 November 2011
  152. 152. Hypermedia another long-time friend Bengaluru, 20-22 November 2011
  153. 153. Linksoutrageously semplifying Bengaluru, 20-22 November 2011
  154. 154. <img src="..." /><a href="..." /><link rel="payment" ... /> Bengaluru, 20-22 November 2011
  155. 155. <img src="..." /><a href="..." /><link rel="payment" ... /> Bengaluru, 20-22 November 2011
  156. 156. <img src="..." /><a href="..." /><link rel="payment" ... /> Bengaluru, 20-22 November 2011
  157. 157. <link rel="payment" href="/checkout" type="text/html" ... /> Bengaluru, 20-22 November 2011
  158. 158. <link rel="payment" href="/checkout" type="text/html" ... /> Bengaluru, 20-22 November 2011
  159. 159. <link rel="payment" href="/checkout" type="text/html" ... /> Bengaluru, 20-22 November 2011
  160. 160. <link rel="payment" href="/checkout" type="text/html" ... /> Bengaluru, 20-22 November 2011
  161. 161. POST /users Host: www.example. comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1 Bengaluru, 20-22 November 2011
  162. 162. POST /users Host: www.example. comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1 Bengaluru, 20-22 November 2011
  163. 163. POST /users Host: www.example. comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1 Bengaluru, 20-22 November 2011
  164. 164. POST /users Host: www.example. comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1 Bengaluru, 20-22 November 2011
  165. 165. consumers of your API are able to follow the changes of your design Bengaluru, 20-22 November 2011
  166. 166. Client knows how to consume theservice based on the informationsauto-provided by the service itself Bengaluru, 20-22 November 2011
  167. 167. No WSDL.Bengaluru, 20-22 November 2011
  168. 168. No URI templates.Bengaluru, 20-22 November 2011
  169. 169. No easily-outdated documentation. Bengaluru, 20-22 November 2011
  170. 170. No assumptions.Bengaluru, 20-22 November 2011
  171. 171. Less WTFs.Bengaluru, 20-22 November 2011
  172. 172. Bengaluru, 20-22 November 2011
  173. 173. This does not easily break. Bengaluru, 20-22 November 2011
  174. 174. HATEOASHypermedia As The Engine Of Application State Bengaluru, 20-22 November 2011
  175. 175. 6Bengaluru, 20-22 November 2011
  176. 176. everythingseems eventually coolRecap: why REST? Bengaluru, 20-22 November 2011
  177. 177. ProsPerformances Bengaluru, 20-22 November 2011
  178. 178. ProsScalability Bengaluru, 20-22 November 2011
  179. 179. Pros DurabilityBengaluru, 20-22 November 2011
  180. 180. Not RESTful? Bengaluru, 20-22 November 2011
  181. 181. Simply dont care Bengaluru, 20-22 November 2011
  182. 182. Rules of architectural design Bengaluru, 20-22 November 2011
  183. 183. Follow them according to your needs Bengaluru, 20-22 November 2011
  184. 184. amazon.comBengaluru, 20-22 November 2011
  185. 185. So...Bengaluru, 20-22 November 2011
  186. 186. Bengaluru, 20-22 November 2011
  187. 187. Alessandro Nadalin Bengaluru, 20-22 November 2011
  188. 188. odino.orgBengaluru, 20-22 November 2011
  189. 189. Bengaluru, 20-22 November 2011
  190. 190. @_odino_ #osidaysBengaluru, 20-22 November 2011
  191. 191. Thank YOU!@_odino_ Bengaluru, 20-22 November 2011
  192. 192. Credits http://www.flickr.com/photos/larachris/16564077/sizes/o/in/photostream/ http://www.flickr.com/photos/ashatenbroeke/4367373081/sizes/z/in/photostream/ http://www.flickr.com/photos/yourdon/3140270189/sizes/l/in/photostream/ http://www.flickr.com/photos/jox1989/4964706072/sizes/l/in/photostream/ http://www.flickr.com/photos/brainfg/168506259/sizes/o/in/photostream/ http://www.flickr.com/photos/norte_it/3897091546/sizes/o/in/photostream/ http://www.zdnet.com/blog/service-oriented/soap-versus-rest-a-matter-of-style/3568http://www.flickr.com/photos/turtlemom_nancy/2046347762/sizes/l/in/photostream/ http://www.flickr.com/photos/juanpg/3333385784/sizes/z/in/photostream/ http://www.flickr.com/photos/congvo/301678287/sizes/l/in/photostream/ http://www.flickr.com/photos/ihasb33r/2573196546/sizes/z/in/photostream/ http://www.flickr.com/photos/martin_heigan/4544138976/sizes/o/in/photostream/ http://www.flickr.com/photos/cknara/4195099999/sizes/o/in/photostream/ http://www.flickr.com/photos/1080p/3076529265/sizes/l/in/photostream/ http://www.flickr.com/photos/adamrice/280300202/sizes/l/in/photostream/ http://www.flickr.com/photos/tomer_a/541411897/sizes/o/in/photostream/ http://www.flickr.com/photos/subpra/4514008262/sizes/l/in/photostream/ http://www.flickr.com/photos/lippincott/2539720043/sizes/l/in/photostream/ http://www.flickr.com/photos/rawryder/5086090931/sizes/l/in/photostream/ http://www.flickr.com/photos/robboudon/5312731161/sizes/l/in/photostream/ http://www.flickr.com/photos/bc-burnslibrary/4158243488/sizes/o/in/photostream/http://www.flickr.com/photos/13606325@N08/2416993706/sizes/o/in/photostream/ http://www.flickr.com/photos/neothezion/5135841069/sizes/l/in/photostream/ http://www.flickr.com/photos/planetschwa/2494067809/ http://www.flickr.com/photos/thomasthomas/258931782/ http://www.flickr.com/photos/rustyboxcars/2629631562/sizes/l/in/photostream/ http://www.flickr.com/photos/ell-r-brown/4138727474/sizes/l/in/photostream/ http://www.flickr.com/photos/noah123/5082076630/sizes/z/in/photostream/ http://www.flickr.com/photos/jungle_boy/220181177/sizes/l/in/photostream/ http://www.flickr.com/photos/prettydaisies/872539081/sizes/l/in/photostream/ http://www.flickr.com/photos/kaptainkobold/76256150/sizes/o/in/photostream/ http://www.flickr.com/photos/uomoincravatta/1438372865/sizes/z/in/photostream/ Bengaluru, 20-22 November 2011

×