Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

DDD & REST Domain Driven Apis for the Web

8,858 views

Published on

SpringOne Platform 2016
Speaker: Oliver Gierke; Spring Data Project Lead, Pivotal

While Domain Driven Design is supposed to take care of complexity in the very core of software, REST is usually treated a plain remoting technology. In this talk we're going to explore some commonalities of the two when it comes to the design of both the domain and resources. We're going to discover how a good domain design is essential to build a great REST API in the first place and which means REST provides to make your APIs more domain driven. From all of the building blocks of DDD, the talk identifies the ones most important when it comes to building a good REST API: we're going to look at aggregates as natural boundaries for representations, repositories as the backing foundation for collection resources and how hypermedia allows to make domain specific state transitions explicit.

Published in: Technology
  • ★★ How Long Does She Want You to Last? ★★ A recent study proved that the average man lasts just 2-5 minutes in bed (during intercourse). The study also showed that many women need at least 7-10 minutes of intercourse to reach "The Big O" - and, worse still... 30% of women never get there during intercourse. Clearly, most men are NOT fulfilling there women's needs in bed. Now, as I've said many times - how long you can last is no guarantee of being a GREAT LOVER. But, not being able to last 20, 30 minutes or more, is definitely a sign that you're not going to "set your woman's world on fire" between the sheets. Question is: "What can you do to last longer?" Well, one of the best recommendations I can give you today is to read THIS report. In it, you'll discover a detailed guide to an Ancient Taoist Thrusting Technique that can help any man to last much longer in bed. I can vouch 100% for the technique because my husband has been using it for years :) Here's the link to the report ♣♣♣ http://ishbv.com/rockhardx/pdf
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

DDD & REST Domain Driven Apis for the Web

  1. 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. 2. Background 3
  3. 3. 4 Spring Data Repositories &
 Aggregates Spring HATEOAS Hypermedia
 for Spring MVC Spring Data REST
  4. 4. When designing REST APIs, what can we learn from DDD? “ 5
  5. 5. What does it take to bridge the worlds of DDD & REST? “ 6
  6. 6. 8 http://www.infoq.com/minibooks/domain-driven-design-quickly
  7. 7. 9
  8. 8. 9
  9. 9. Implementing Domain-Driven Design 10
  10. 10. Value objects 11
  11. 11. Stringly typed code 12 public class Customer { private Long id; private String firstname, lastname, email; … }
  12. 12. Stringly typed code 13 public class SomeService { public void createUser(String firstname,
 String lastname, String email) { … } }
  13. 13. 14 public class Customer { private Long id; private Firstname firstname; private Lastname lastname; private EmailAddress emailAddress; … }
  14. 14. Value Objects are a
 PITA to build in
 some languages. 15
  15. 15. Still, they’re worth it. 16 See „Power Use of Value Objects in DDD“ by Dan Bergh Johnsson.
  16. 16. Lombok — putting the spice back into Java. 17
  17. 17. 18 @Value public class Customer { UUID id = UUID.randomUUID(); Firstname firstname; Lastname lastname; EmailAddress email; @Value static class EmailAddress { String value; } }
  18. 18. AutoValue 19 Project website on GitHub.
  19. 19. Entities & Repositories 20
  20. 20. 21 Order LineItem Product Invoice Customer Payment Address Email
  21. 21. 21 Order LineItem Product Invoice Customer Payment Address Email
  22. 22. Entity +
 Repository = 
 Aggregate 22
  23. 23. Aggregates.
 Scopes of consistency. 23
  24. 24. 24 Order LineItem Product Invoice Customer Payment Address Email
  25. 25. Aggregates.
 The key things
 to refer to. 25
  26. 26. 26 Order LineItem Product Invoice Customer Payment Address Email
  27. 27. Don’t get trapped by datastore thinking. 27
  28. 28. 28 Order LineItem Product Invoice Customer Payment Address Email
  29. 29. Bounded Context 29
  30. 30. Order LineItem Product Invoice Customer Payment Address
  31. 31. 31 Shipping Accounting Catalog Orders User
 Registration
  32. 32. 31 Shipping Accounting Catalog Orders User
 Registration Accounting Payment information Billing Address Shipping Shipping address Customer
  33. 33. 31 Shipping Accounting Catalog Orders User
 Registration Accounting Payment information Billing Address Shipping Shipping address Customer Product
  34. 34. Domain Events 32
  35. 35. 33 Level 0: No events at all
  36. 36. 33 Level 0: No events at all Level 1: Explicit operations
  37. 37. If you’re calling two setters in a row, you’re missing a concept. 34
  38. 38. 35 Level 0: No events at all Level 1: Explicit operations Level 2: Some operations as events
  39. 39. Domain events as
 state transitions. 36
  40. 40. Expose important
 events to interested parties via feeds. 37
  41. 41. 38 Level 0: No events at all Level 1: Explicit operations Level 2: Some operations as events Level 3: Event Sourcing
  42. 42. REST 39
  43. 43. REST ≠ 
 CRUD via HTTP 40
  44. 44. Representation design matters 41
  45. 45. Value objects
 need custom 
 serializers. 42
  46. 46. Aggregates Identifiable
 Referable
 Scope of consistency 43
  47. 47. Resources Identifiable
 Referable
 Scope of consistency 44
  48. 48. Serving data and navigation information
 at the same time. 46
  49. 49. Trading domain knowledge with protocol complexity in clients. 47
  50. 50. 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
  51. 51. API evolvability is key
 in a system of systems 49
  52. 52. 50 GET /orders { „_links“ : { „cancel“ : { „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
  53. 53. 51 GET /orders { „_links“ : { „cancel“ : { „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
  54. 54. 52 “Internationalize
 all user facing text.
  55. 55. Aaaargh! 53
  56. 56. 54 GET /orders { „_links“ : { „cancel“ : { „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
  57. 57. Reducing decisions in clients to whether a
 link is present or not. 55
  58. 58. Prefer explicit 
 state transitions over poking at your resources using PATCH. 56
  59. 59. Translate domain concepts into web- appropriate ones. 57
  60. 60. 58 Aggregate Root / Repository Collection / Item Resources IDs URIs @Version ETags Last Modified Property Last Modified Header Relations Links
  61. 61. RESTBuckspayment expected preparing cancelled ready completed 1 2 3 4 5 6
  62. 62. 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
  63. 63. 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
  64. 64. Spring RESTBucks 62
  65. 65. Web Service Repository - Orders Spring Data Spring Data
 REST Payment Spring Data Manual
 implementation Manual
 implementation
  66. 66. Resources 67 Spring RESTBucks
 https://github.com/olivergierke/spring-restbucks Benefits of Hypermedia APIs
 http://olivergierke.de/2016/04/benefits-of-hypermedia/index.html
  67. 67. Questions? 68

×