the counterintuitive web
play

The Counterintuitive Web Ian Robinson http://ian S - PowerPoint PPT Presentation

Global Bank Integration The Counterintuitive Web Ian Robinson http://ian S robinson.com @ian S robinson ian S robinson@gmail.com Resources are information resources, not domain objects


  1. Global Bank Integration The ¡Counterintuitive ¡Web ¡ Ian ¡Robinson ¡ http://ian S robinson.com ¡ @ian S robinson ¡ ian S robinson@gmail.com ¡

  2. Resources ¡are ¡information ¡resources, ¡not ¡domain ¡objects ¡ Person ¡ Person ¡ Resource ¡ Order ¡ Order ¡ Resource ¡

  3. Design ¡smell: ¡overloaded ¡POST ¡ Overloaded ¡POST ¡ Server ¡has ¡to ¡peer ¡inside ¡entity ¡body ¡ POST /orders/123 HTTP/1.1 Host: restbucks.com <loyalty-card> ... </loyalty-card> POST /orders/123 HTTP/1.1 Host: restbucks.com <drink> ... </drink>

  4. Design ¡smell: ¡other ¡overloads ¡ Other ¡overloads ¡ Server ¡has ¡to ¡interrogate ¡resource ¡state ¡ prior ¡ to ¡ dispatching ¡to ¡appropriate ¡handler ¡ getState() Cancel ¡ DELETE /orders/123 HTTP/1.1 Host: restbucks.com DELETE /orders/123 HTTP/1.1 Complete ¡ Host: restbucks.com cancel()

  5. Operation-­‑oriented ¡vs. ¡resource-­‑oriented ¡design ¡ CreateOrder ¡ SearchOrders ¡ Operations ¡ AmendOrder ¡ ReserverOrder ¡ CompleteOrder ¡ CancelOrder ¡ RemoveDrink ¡ AddDrink ¡ GET ¡ GET ¡ Resources ¡ PUT ¡ PUT ¡ GET ¡ POST ¡ POST ¡ PUT ¡ DELETE ¡ DELETE ¡ POST ¡ Drink ¡ DELETE ¡ Order ¡ Fulfillment ¡

  6. Specialization ¡and ¡innovation ¡depend ¡on ¡an ¡open ¡set ¡ CreateOrder ¡ SearchOrders ¡ AddDrink ¡ ReserverOrder ¡ CompleteOrder ¡ CancelOrder ¡ AmendOrder ¡ RemoveDrink ¡ GET ¡ PUT ¡ POST ¡ DELETE ¡ GET ¡ PUT ¡ POST ¡ DELETE ¡

  7. HTTP ¡verbs ¡ Verb ¡ Safe? ¡ Description ¡ Idempotent? ¡ √ ¡ √ ¡ GET ¡ Retrieve ¡representation ¡ χ ¡ √ ¡ PUT ¡ Store ¡representation ¡ χ ¡ χ ¡ Annotate, ¡append ¡to ¡ POST ¡ resource ¡identified ¡by ¡URI ¡ χ ¡ √ ¡ DELETE ¡ Delete ¡resource ¡ Safe ¡ No ¡side-­‑effects ¡for ¡which ¡client ¡is ¡responsible ¡ Idempotent ¡ “Absolute” ¡side ¡effects ¡

  8. DELETE ¡!= ¡cancel: ¡don’t ¡map ¡domain ¡operations ¡onto ¡verbs ¡ HTTP ¡verbs ¡are ¡the ¡humble ¡servants ¡of ¡ the ¡hypermedia ¡state ¡apparatus ¡ Stable, ¡well-­‑understood ¡characteristics ¡ Safety ¡ Idempotency ¡ Do ¡the ¡same-­‑old-­‑same-­‑old ¡in ¡the ¡same-­‑old ¡way ¡ Transferring ¡representations ¡of ¡state ¡ No ¡surprises ¡ No ¡additional ¡semantics ¡ No ¡innovation ¡

  9. Clients ¡deal ¡with ¡URIs ¡(and ¡representations), ¡not ¡resources ¡ Resources ¡can ¡be ¡iden.fied ¡and ¡addressed ¡by ¡mul.ple ¡URIs ¡ http://restbucks.com:8080/s/ref=gh_ty_1256 http://restbucks.com:8080/s/ref=gh_ty_1256 ? ¡ http://restbucks.com:8080/s/latest http://restbucks.com:8080/s/latest Problems ¡ Cannot ¡determine ¡URI ¡equality ¡ Cache ¡invalidation ¡

  10. Design ¡smell: ¡overloaded ¡POST ¡ Overloaded ¡POST ¡ Server ¡has ¡to ¡peer ¡inside ¡entity ¡body ¡ POST /orders/123 HTTP/1.1 POST /orders/123/discounts HTTP/1.1 Host: restbucks.com Host: restbucks.com <loyalty-card> <loyalty-card> ... ... </loyalty-card> </loyalty-card> POST /orders/123 HTTP/1.1 POST /orders/123 HTTP/1.1 Host: restbucks.com Host: restbucks.com <drink> <drink> ... ... </drink> </drink>

  11. Design ¡smell: ¡other ¡overloads ¡ Other ¡overloads ¡ Server ¡has ¡to ¡interrogate ¡resource ¡state ¡ prior ¡ to ¡ dispatching ¡to ¡appropriate ¡handler ¡ getState() Cancel ¡ DELETE /orders/123 HTTP/1.1 Host: restbucks.com Cancel ¡ DELETE /orders/123 HTTP/1.1 cancel() DELETE /orders/123 HTTP/1.1 Host: restbucks.com Complete ¡ Host: restbucks.com cancel() complete() POST /orders/123/end HTTP/1.1 Complete ¡ Host: restbucks.com

  12. Intention ¡should ¡be ¡“written ¡on ¡the ¡wire” ¡ Part ¡ Description ¡ URI ¡ Identifies ¡target ¡of ¡request ¡ Document-­‑oriented ¡method ¡semantics, ¡plus ¡ Verb ¡ idempotency ¡and ¡safety ¡expectations ¡ Accept/ Preferred ¡representation ¡format ¡and ¡ Content-­‑Type ¡ information ¡element ¡processing ¡model ¡ Other ¡headers ¡ Additional ¡processing ¡context ¡

  13. Guaranteed ¡delivery? ¡GET ¡it ¡yourself ¡ Order ¡ ¡ Management ¡ Co-­‑located, ¡time-­‑ordered ¡entries ¡ No ¡lost ¡or ¡out-­‑of-­‑order ¡messages ¡ GET ¡is ¡safe ¡and ¡idempotent ¡ Same ¡ result ¡ Atom ¡Client ¡ Different ¡ data ¡ http://restbucks.com/products/notifications Product ¡ Management ¡ Atom ¡icons ¡from ¡http://sniker.blogage.de/ ¡

  14. HTTP ¡= ¡??? ¡

  15. HTTP: ¡an ¡application ¡transfer ¡protocol ¡ Term ¡ Description ¡ Transacted ¡at ¡application ¡layer ¡of ¡network ¡ Application ¡ stack, ¡in ¡user ¡agent ¡and ¡server ¡software ¡ For ¡the ¡purpose ¡of ¡coordinating ¡the ¡transfer ¡ Transfer ¡ of ¡documents ¡ According ¡to ¡rules ¡that ¡determine ¡legitimate ¡ Protocol ¡ interactions ¡between ¡client ¡and ¡server ¡

  16. Benefits ¡ Coordination ¡protocol ¡(status ¡codes) ¡ + ¡ Self-­‑describing ¡processing ¡context ¡(headers) ¡ + ¡ Safety ¡and ¡idempotency ¡characteristics ¡(verbs) ¡ Optimize ¡for ¡the ¡common ¡case ¡ = ¡ GET ¡

  17. GET ¡connected: ¡design ¡for ¡caching ¡ Inside ¡corporate ¡firewall ¡ Standalone ¡(intermediary) ¡ Server ¡ Caching ¡proxy ¡ Local ¡cache ¡ Reverse ¡proxy ¡ Client ¡ Service ¡scalability ¡ Memory ¡ Disk ¡

  18. Cache ¡by ¡freshness ¡ Server/ Client ¡ Cache ¡ Cache ¡ Server ¡ Local ¡cache ¡ Client ¡ See ¡also: ¡http://martinfowler.com/bliki/SegmentationByFreshness.html ¡

  19. A ¡web ¡of ¡data ¡ @mfeathers: ¡Good ¡OO ¡= ¡Tell, ¡don't ¡ask. ¡Good ¡FP ¡= ¡ Ask, ¡don't ¡tell. ¡#speakerconf ¡ OO ¡relationship ¡between ¡things, ¡FP ¡relationship ¡ between ¡facts ¡(@marick) ¡#speakerconf ¡ Web ¡is ¡the ¡par.al ¡applica.on ¡of ¡data ¡to ¡a ¡ user ¡or ¡applica.on ¡goal ¡ Residual ¡data ¡structures ¡wai.ng ¡to ¡be ¡ completed ¡by ¡the ¡transfer ¡of ¡another ¡ representa.on ¡of ¡state ¡

  20. Facts: ¡that’s ¡data, ¡and ¡CRUD, ¡right? ¡ “[our ¡customers] ¡base ¡their ¡success ¡on ¡ us ¡failing ¡in ¡the ¡same ¡way” ¡ “Instead ¡of ¡being ¡behavior-­‑centric ¡with ¡ our ¡computer ¡systems, ¡we ¡look ¡at ¡them ¡ as ¡just ¡being ¡CRUD, ¡ and ¡we ¡basically ¡say ¡we ¡are ¡going ¡to ¡ ignore ¡the ¡fact ¡that ¡we ¡are ¡going ¡to ¡do ¡ anything ¡with ¡them” ¡ Greg ¡Young ¡on ¡Our ¡Grand ¡Failure ¡ h@p://herdingcode.com/?p=189 ¡

  21. Achieving ¡balance: ¡design ¡and ¡implementation ¡guidelines ¡ 1. Design ¡applica.ons ¡in ¡terms ¡of ¡ applica&on ¡protocol ¡state ¡machines ¡ ¡ 2. Implement ¡them ¡in ¡terms ¡of ¡ resource ¡ lifecycles ¡ and ¡the ¡ rules ¡that ¡associate ¡ resources ¡ 3. Adver.se/document ¡them ¡using ¡ media ¡ types , ¡ link ¡rela&on ¡values ¡ and ¡ HTTP ¡ idioms ¡ Web ¡

  22. Application ¡protocol, ¡application ¡state ¡ Application ¡protocol ¡ Application ¡state ¡

  23. Order ¡fulfillment ¡application ¡protocol ¡ awaiting fulfillment remove barista drink accepts add drink fulfilling correcting order modified drinks == line items fulfilled

  24. Order ¡fulfillment ¡protocol ¡resources ¡ details fulfillment contains items not in details started created requires preparing corrected amending destroyed completed made placed discarded fulfilling fulfillment = consumed completed ready drink order

  25. Resource ¡state ¡is ¡a ¡function ¡of… ¡ 1. Value ¡of ¡information ¡items ¡belonging ¡to ¡resource ¡ 2. Application ¡of ¡business ¡rules ¡that ¡relate ¡a ¡resource ¡ to ¡other ¡resources ¡ GET ¡ See ¡also ¡FOREST: ¡Functional ¡Observer ¡REST ¡ http://duncan-­‑cragg.org/blog/post/forest-­‑functional-­‑observer-­‑rest/ ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend