REST in peace @ IPC 2012 in Mainz

1,160 views

Published on

Presentation given at the International PHP Conference 2012 in Mainz, about the REST architectural style.

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

No Downloads
Views
Total views
1,160
On SlideShare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

REST in peace @ IPC 2012 in Mainz

  1. 1. Alessandro Nadalin | NAMSHI.comREST in peace
  2. 2. AGENDA●Vol. 1: REST in a nutshell ○Tenets ○Antipatterns●Vol. 2: To the rescue ○HTTP cache ○HATEOAS
  3. 3. Sorry for the ugly slide. There will be others. Really sorry.
  4. 4. REST in a nutshell:1. Client <> Server
  5. 5. REST in a nutshell: 2. Stateless
  6. 6. REST in a nutshell: 3. Cacheable
  7. 7. REST in a nutshell:4. Layered system
  8. 8. REST in a nutshell: 5. Uniform interface
  9. 9. And obviously nobody had a clue
  10. 10. ANTIPATTERNS
  11. 11. 1URIs
  12. 12. "REST is about cool URI design"http://apple.com/users/1/licenses/4.json
  13. 13. "REST is about cool URI design"http://apple.com/users/1/licenses/4.json
  14. 14. http://apple.com/site/en_US/showUsers.jsp? uid=1&license=4 is OK too
  15. 15. but
  16. 16. cool URIs help youthink in term of resources David Zuelke
  17. 17. 2URIs (bis)
  18. 18. REST follows a URI schema GET /users POST /users PUT /users/{id} DELETE /users/{id} ...
  19. 19. REST follows a URI schema GET /users POST /users PUT /users/{id} DELETE /users/{id} ...
  20. 20. what if you change your URL?
  21. 21. Yeah,client isbroken
  22. 22. RESTful clients should be driven by services hypermedia controlsRoy Fielding : http://roy.gbiv.com/untangled/2008/rest-apis-must-be- hypertext-driven
  23. 23. HATEOAS
  24. 24. 3POST is cool
  25. 25. said SOAP 1.1
  26. 26. said SOAP 1.1
  27. 27. loosing meaningful verbs at the protocol level
  28. 28. loosing meaningful verbs at the protocol level nothing cacheable by default
  29. 29. loosing meaningful verbs at the protocol level nothing cacheable by default what about bookmarking?
  30. 30. 4500 is your friend
  31. 31. said SOAP ( again )
  32. 32. GET /users/300Host: www.example.com
  33. 33. GET /users/300 Host: www.example. comHTTP/1.1 500 Internal ServerErrorEtag: 1234X-Powered-By: php/5.3...The record cannot be found
  34. 34. GET /users/300 Host: www.example. comHTTP/1.1 500 Internal ServerErrorEtag: 1234X-Powered-By: php/5.3...The record cannot be found
  35. 35. The HTTP protocol is awesome,and lets you return meaningful anduniversally-understood status codes
  36. 36. 404 Not Found
  37. 37. 202 Accepted
  38. 38. 202 AcceptedYou get an immediate OK, and the operation will hopefully complete
  39. 39. Pause
  40. 40. World Wide Web
  41. 41. the largest data-exchange network on the planet
  42. 42. And meanwhile, at Facebook...12TB of new data every day (2 years ago) 500 million users
  43. 43. And meanwhile, at Google... 1 billionunique monthly googlers
  44. 44. via HTTP , baby!
  45. 45. HTTP in a nutshell:1. Client <> Server
  46. 46. HTTP in a nutshell: 2. Stateless
  47. 47. HTTP in a nutshell: 3. widespread cache spechttp://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html
  48. 48. HTTP in a nutshell: Firefox Company proxy Great chinese (fire)wall Reverse proxy Origin server 4. Layered system
  49. 49. HTTP in a nutshell: 5. it is the uniform interface between clients and servers
  50. 50. HTTP bleeds REST
  51. 51. 1.caching & scalability
  52. 52. Types of cache Local Shared/proxy Shared/reverse proxy
  53. 53. Types of cache Local Shared/proxy Shared/reverse proxy
  54. 54. Types of cache Local Shared/proxy Shared/reverse proxy
  55. 55. Types of cache Local Shared/proxyShared/reverse proxy
  56. 56. on the server side
  57. 57. Caching with Expiration (example)
  58. 58. HTTP/1.1 200 OKHost: www.example.comExpires: 0
  59. 59. HTTP/1.1 200 OKHost: www.example.comExpires: 0
  60. 60. HTTP/1.1 200 OKHost: www.example.comExpires: Tue, 31 Jan 2013 01:00 GMT
  61. 61. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public
  62. 62. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public
  63. 63. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public Cacheable for 60 seconds
  64. 64. HTTP/1.1 200 OK Host: www.example.com Cache-Control: max-age=60, publicCacheable by both local and shared caches
  65. 65. but hey, you say
  66. 66. 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 )
  67. 67. NopeNope
  68. 68. ESI was built for that http://www.w3.org/TR/esi-lang
  69. 69. <esi:include src="http://php2start.com/talks/1" />
  70. 70. <esi:include src="http://php2start.com/talks/1" />
  71. 71. <esi:include src="http://php2start.com/talks/1" />
  72. 72. 1s (tweets)3600 post
  73. 73. <esi:include src=tweets.html /><esi:include src=article/12.html />
  74. 74. So what does HTTP cache is meant to solve?
  75. 75. Less work
  76. 76. http://www.flickr.com/photos/snakphotography/5004775320/sizes/o/in/photostream/because the hard work is delegated to the browser/proxy
  77. 77. evolve
  78. 78. because cache is abstracted from the application
  79. 79. loose coupling
  80. 80. because caching is bound to the protocol, HTTP, notto your implementation ( Sf, RoR, Django )
  81. 81. 2.adaptability & durability
  82. 82. Hypermedia another long-time friend
  83. 83. Linksoutrageously simplifying
  84. 84. <link rel="payment" href="/checkout" type="text/html" ... />
  85. 85. <link rel="payment" href="/checkout" type="text/html" ... />
  86. 86. <link rel="payment" href="/checkout" type="text/html" ... />
  87. 87. <link rel="payment" href="/checkout" type="text/html" ... />
  88. 88. POST /users Host: www.example. comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1
  89. 89. POST /users Host: www.example. comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1
  90. 90. POST /users Host: www.example. comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1
  91. 91. POST /users Host: www.example. comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1
  92. 92. consumers of your API are able to follow the changes of your design
  93. 93. everything seems cool But why REST?
  94. 94. ProsPerformances
  95. 95. ProsScalability
  96. 96. Pros Durability
  97. 97. amazon.com
  98. 98. Alex Nadalin
  99. 99. Alex Nadalin odino.org
  100. 100. Alex Nadalin odino.org @_odino_
  101. 101. Alex Nadalin odino.org @_odino_
  102. 102. Alex Nadalin odino.org @_odino_
  103. 103. Alex Nadalin odino.org DXB @_odino_
  104. 104. Alex Nadalin odino.org DXB @_odino_
  105. 105. Were hiring!
  106. 106. In Dubai.
  107. 107. In Dubai.alex.nadalin@namshi.com
  108. 108. In Dubai.alex.nadalin@namshi.com @_odino_
  109. 109. In Dubai.alex.nadalin@namshi.com @_odino_ TALK TO ME!
  110. 110. 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/

×