Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DDD & REST — Domain-Driven APIs for the web

DDD & REST — Domain-Driven APIs for the web

Slides of the talk I gave at SpringOne Platform, Las Vegas

Avatar for Oliver Drotbohm

Oliver Drotbohm

August 02, 2016
Tweet

More Decks by Oliver Drotbohm

Other Decks in Programming

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ DDD & REST
 Domain-Driven APIs for the web Oliver Gierke / olivergierke ogierke@pivotal.io
  2. 9

  3. 9

  4. Stringly typed code 12 public class Customer { private Long

    id; private String firstname, lastname, email; … }
  5. Stringly typed code 13 public class SomeService { public void

    createUser(String firstname,
 String lastname, String email) { … } }
  6. 14 public class Customer { private Long id; private Firstname

    firstname; private Lastname lastname; private EmailAddress emailAddress; … }
  7. Still, they’re worth it. 16 See „Power Use of Value

    Objects in DDD“ by Dan Bergh Johnsson.
  8. 18 @Value public class Customer { UUID id = UUID.randomUUID();

    Firstname firstname; Lastname lastname; EmailAddress email; @Value static class EmailAddress { String value; } }
  9. 31 Shipping Accounting Catalog Orders User
 Registration Accounting Payment information

    Billing Address Shipping Shipping address Customer Product
  10. 35 Level 0: No events at all Level 1: Explicit

    operations Level 2: Some operations as events
  11. 38 Level 0: No events at all Level 1: Explicit

    operations Level 2: Some operations as events Level 3: Event Sourcing
  12. 48 Amount of domain knowledge in the client Amount of

    protocol knowledge in the client Coupling to the server Non-hypermedia
 based systems Hypermedia
 based systems
  13. 50 GET /orders { „_links“ : { „cancel“ : {

    „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
  14. 51 GET /orders { „_links“ : { „cancel“ : {

    „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
  15. 54 GET /orders { „_links“ : { „cancel“ : {

    „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
  16. 58 Aggregate Root / Repository Collection / Item Resources IDs

    URIs @Version ETags Last Modified Property Last Modified Header Relations Links
  17. Method URI Action Step POST /orders Create new order 1

    POST/PATCH /orders/{id} Update the order (only if "payment expected") 2 DELETE /orders/{id} Cancel order (only if "payment expected") 3 PUT /orders/{id}/payment Pay order (only if "payment expected") 4 Barista preparing the order GET /orders/{id} Poll order state 5 GET /orders/{id}/receipt Access receipt DELETE /orders/{id}/receipt Conclude the order process 6
  18. Method Resource type Action Step POST orders Create new order

    1 POST/PATCH update Update the order 2 DELETE cancel Cancel order 3 PUT payment Pay order 4 Barista preparing the order GET order Poll order state 5 GET receipt Access receipt DELETE receipt Conclude the order process 6
  19. Web Service Repository - Orders Spring Data Spring Data
 REST

    Payment Spring Data Manual
 implementation Manual
 implementation