ddd rest
play

DDD & REST Domain-Driven APIs for the web Oliver Gierke / - PowerPoint PPT Presentation

DDD & REST Domain-Driven APIs for the web Oliver Gierke / olivergierke 2 Background 3 Spring Data REST Spring Data Spring HATEOAS Repositories & Hypermedia Aggregates for Spring MVC 4 REST CRUD via HTTP 5


  1. DDD & REST Domain-Driven APIs for the web Oliver Gierke � / � olivergierke

  2. 2

  3. Background 3

  4. Spring Data REST Spring Data Spring HATEOAS Repositories & 
 Hypermedia 
 Aggregates for Spring MVC 4

  5. REST ≠ 
 CRUD via HTTP 5

  6. “ What does it take to bridge the worlds of DDD & REST?

  7. 7

  8. 7

  9. Value objects 8

  10. Value Objects are a 
 PITA to build in 
 some languages. 9

  11. Still, they’re worth it. See „Power Use of V alue Objects in DDD“ by Dan Bergh Johnsson. 10

  12. Lombok — putting the spice back into Java. 11

  13. Key opponents: Mapping libraries 
 that need to 
 (de)serialize them. 12

  14. Entities & Repositories 13

  15. 14

  16. Email Customer Payment Address 14

  17. Email Customer Payment Address Invoice 14

  18. Email Customer Payment Address Order Invoice LineItem 14

  19. Email Customer Payment Address Product Order Invoice LineItem 14

  20. Email Customer Payment Address Product Order Invoice LineItem 14

  21. Entity + 
 Repository = 
 Aggregate 15

  22. Aggregates form nice representation boundaries. 16

  23. Aggregates become 
 the key things 
 to refer to. 17

  24. Don’t get trapped by datastore thinking. 18

  25. Try to avoid 
 bi-directional relationships. 19

  26. Domain Events 20

  27. Level 0: No events at all 21

  28. Level 1: Explicit operations Level 0: No events at all 21

  29. If you’re calling two setters in a row, you’re missing a concept. 22

  30. Level 2: Some operations as events Level 1: Explicit operations Level 0: No events at all 23

  31. Domain events as 
 state transitions. 24

  32. Expose important 
 events to interested parties via feeds. 25

  33. Level 3: Event Sourcing Level 2: Some operations as events Level 1: Explicit operations Level 0: No events at all 26

  34. REST 27

  35. Representation design matters 28

  36. Aggregates Identifiable 
 Referable 
 Scope of consistency 29

  37. Resources Identifiable 
 Referable 
 Scope of consistency 30

  38. Hypermedia 31

  39. Serving data and navigation information 
 at the same time. 32

  40. Trading domain knowledge with protocol complexity in clients. 33

  41. Reducing decisions in clients to whether a 
 link is present or not. 34

  42. Prefer explicit 
 state transitions over poking at your resources using PATCH. 35

  43. Translate domain concepts into web- appropriate ones. 36

  44. Aggregate Root / Collection / Item Repository Resources Relations Links IDs URIs @Version ETags Last Modified Last Modified Property Header 37

  45. RESTBucks

  46. 5 6 preparing ready completed 2 4 1 RESTBucks payment expected 3 cancelled

  47. Method URI Action Step POST /orders Create new order 1 Update the order POST/PATCH /orders/{id} 2 (only if "payment expected") Cancel order DELETE /orders/{id} 3 (only if "payment expected") Pay order PUT /orders/{id}/payment 4 (only if "payment expected") 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

  48. 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

  49. Spring RESTBucks 41

  50. Orders Payment Spring Data 
 Manual 
 Web REST implementation Manual 
 - Service implementation Repository Spring Data Spring Data

  51. JacksonCustomizations Externalize tweaks to the general JSON design 43

  52. Spring Data REST 
 for the CRUDdy parts. 44

  53. ResourceProcessor To conditionally sneak links into the default representation. 45

  54. Code Spring RESTBucks - https://github.com/olivergierke/spring-restbucks 46

  55. Questions? 47

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