over
presentation                                http    business     logicproblem 1:presentation depends on the interactionflo...
presentation                                http   business    logic                 presentation                         ...
presentation                                http   business    logic                 presentation                         ...
presentation                                http   business    logic                 presentation                         ...
n                                         io                 presentation                                       t         ...
n                                          io                  presentation                                        t      ...
n                                                                io                                        presentation   ...
n                                           io                   presentation                                         t   ...
logic                                                                 business                                            ...
business                                                                        logic                                     ...
presentation               presentation                              http  business   logic                               ...
presentation              business                                        http               usage               logic bus...
presentation business  logic            http                                  presentationadopted solution
SmartphoneClient.prototype.next = function() {  var self = this  this.seq(     this.purchase,     this.transferIn,     thi...
presentationbusiness logic           http                                 presentation  clear separationfrom application a...
presentation    business     logic               http                                     presentation  stateless: easy to...
$app->post("/purchase/:id/transfer-in/opt-in/pin",    function($purchaseId) use($app) {        ContentDelivery::on($app)  ...
presentation   business    logic              http                                    presentationclear application interf...
$app->map("/purchases", ...$app->get("/purchase/:id", ...$app->post("/purchase/:id/login", ...$app->get("/purchase/:id/buy...
presentationbusiness logic           http                                     presentation                  testable
public function testShouldLoginWithARegisteredMsisdn(){    $self = $this;    $msisdn = Baker::bake("Msisdn", "registered")...
business     logic               http                              presentation    what   about              presentationo...
businessnow                  logic                   http                                     presentation                ...
namespace HttpFeaturePhone{    class Client    {        public function next()        {            try {                 $...
presentation                                    http   business    logic              http                                ...
questions?
Upcoming SlideShare
Loading in...5
×

API Over HTTP

8,897

Published on

Published in: Technology
2 Comments
22 Likes
Statistics
Notes
No Downloads
Views
Total Views
8,897
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
89
Comments
2
Likes
22
Embeds 0
No embeds

No notes for slide

API Over HTTP

  1. 1. over
  2. 2. presentation http business logicproblem 1:presentation depends on the interactionflow, and mobile flows are reallydifferent
  3. 3. presentation http business logic presentation httpproblem 2:conversation state shared between clientand server. conversation state onserver leads to “session abuse”
  4. 4. presentation http business logic presentation httpproblem 2:conversation state shared between clientand server. conversation state onserver leads to “session abuse”
  5. 5. presentation http business logic presentation httpproblem 2:conversation state shared between clientand server. conversation state onserver leads to “session abuse”
  6. 6. n io presentation t http a s e business logic r t e a v t presentation n s http c oproblem 2:conversation state shared between clientand server. conversation state onserver leads to “session abuse”
  7. 7. n io presentation t http aap s e pl business logic ic r t e a st at v t presentation at io n s http e n c oproblem 2: conversation state shared between client and server. conversation state on server leads to “session abuse”
  8. 8. n io presentation t http aap s e pl business r t presentation http business logic presentation http e a logic ic st at v t presentation at io n s http e n c oproblem 2: (sessions) could make horizontal scalability harder than it should be
  9. 9. n io presentation t http aap s e pl business logic ic r t e a st at v t presentation at io n s http e n c oproblem 2: (sessions) it’s very hard to migrate conversations from agents (mobile <-> desktop)
  10. 10. logic business business business logic logic usage usage presentation presentation problem 3: http httpbusiness logic usage is duplicated
  11. 11. business logic problem 3: business business logic logic (duplication) usage usage presentation presentation http httpworst when there’s an anemic domain model
  12. 12. presentation presentation http business logic presentation presentation httpproblem 4: rich clientmore duplication (different languages),more difficult to separateresponsibilities (where is what?)
  13. 13. presentation business http usage logic business logic presentation business http usage logicproblem 5: (testability)difficult to reach a particular point inthe conversation. presentation changesoften (smell: divergent change)
  14. 14. presentation business logic http presentationadopted solution
  15. 15. SmartphoneClient.prototype.next = function() { var self = this this.seq( this.purchase, this.transferIn, this.optIn, this.waitForCompletion ).exit(function(exit) { exit.callHandler(self.callbacks) })} var client = new SmartphoneClient(server, { onError: function(error) { app.pages.notify.error(error) }, onRoute: function(route) { app.goTo(route) }, onUrl: function(url) { location.href = url } })
  16. 16. presentationbusiness logic http presentation clear separationfrom application and conversation state
  17. 17. presentation business logic http presentation stateless: easy to scalehorizontally, conversations can be migrated/resumed
  18. 18. $app->post("/purchase/:id/transfer-in/opt-in/pin", function($purchaseId) use($app) { ContentDelivery::on($app) ->process(function($request, $response) use($purchaseId, $app) { $purchase = Purchase::fromRequest($request, $purchaseId); $transferIn = $purchase->boundedTransferIn("pin-flow"); $transferIn->checkPin($request->params("pin")); $response->status(200); }) ->rescue(OnebipCoreNotSupportedActionInState, 409) ->rescue(OnebipPurchasePurchaseNotFound, 404) ->rescue(OnebipPurchaseTransferInNotFound, 404) ->rescue(OnebipPurchaseSpendingLimitReached, 403) ->rescue(OnebipPurchaseCheckPinFailed, 400) ->rescue(HttpUnauthenticatedRequest, 401) ->deliver(); }); look, no session, and the controller code is really small
  19. 19. presentation business logic http presentationclear application interface
  20. 20. $app->map("/purchases", ...$app->get("/purchase/:id", ...$app->post("/purchase/:id/login", ...$app->get("/purchase/:id/buyer", ...$app->post("/purchase/:id/transfers-in", ...$app->get("/purchase/:id/transfer-in", ...$app->put("/purchase/:id/transfer-in", ...$app->post("/purchase/:id/transfer-in/opt-in/pin", ...$app->put("/purchase/:id/transfer-in/mo", ... clear application interface
  21. 21. presentationbusiness logic http presentation testable
  22. 22. public function testShouldLoginWithARegisteredMsisdn(){ $self = $this; $msisdn = Baker::bake("Msisdn", "registered"); $purchase = Baker::bake("Purchase", "from Country", $msisdn->country()); $insertByUser = $msisdn->withoutNationalPrefixAsString(); $this->request("POST", "/purchase/{$purchase->id()}/login") ->withBody(array("msisdn" => $insertByUser)) ->run(function($response) use ($self) { $self->assertEquals(201, $response->status()); });} testable
  23. 23. business logic http presentation what about presentationold phones?
  24. 24. businessnow logic http presentation http presentation presentation
  25. 25. namespace HttpFeaturePhone{ class Client { public function next() { try { $this->purchase(); $this->transferIn(); $this->optIn(); $this->waitForCompletion(); } catch (ClientExit $exit) { $exit->callHandler($this->callbacks); } catch (Exception $e) { $exit = new ClientExit("error", $e->getMessage()); $exit->callHandler($this->callbacks); } } ... }} $client = new HttpFeaturePhoneClient($server, array( "onError" => function($error) use ($app) { $app->flash($error); $app->redirectTo($app->urlFor("error-ui")); }, "onRoute" => function($route) use ($app) { $app->renderOrRedirectTo($route); }, "onUrl" => function($url) use ($app) { $app->redirectTo($url); } ));
  26. 26. presentation http business logic http presentation presentationtomorrow...
  27. 27. questions?
  1. A particular slide catching your eye?

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

×