DDD & REST Domain-Driven APIs for the web Oliver Gierke / - - PowerPoint PPT Presentation
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
Background
3Spring Data
Repositories & AggregatesSpring HATEOAS
Hypermedia for Spring MVCSpring Data REST
REST ≠ CRUD via HTTP
5What does it take to bridge the worlds of DDD & REST?
“
Value objects
8Value Objects are a PITA to build in some languages.
9Still, they’re worth it.
10 See „Power Use of V alue Objects in DDD“ by Dan Bergh Johnsson.Lombok — putting the spice back into Java.
11Key opponents: Mapping libraries that need to (de)serialize them.
12Entities & Repositories
13Entity + Repository = Aggregate
15Aggregates form nice representation boundaries.
16Aggregates become the key things to refer to.
17Don’t get trapped by datastore thinking.
18Try to avoid bi-directional relationships.
19Domain Events
20If you’re calling two setters in a row, you’re missing a concept.
22Domain events as state transitions.
24Expose important events to interested parties via feeds.
25REST
27Representation design matters
28Aggregates
Identifiable Referable Scope of consistency
29Resources
Identifiable Referable Scope of consistency
30Hypermedia
31Serving data and navigation information at the same time.
32Trading domain knowledge with protocol complexity in clients.
33Reducing decisions in clients to whether a link is present or not.
34Prefer explicit state transitions over poking at your resources using PATCH.
35Translate domain concepts into web- appropriate ones.
36RESTBucks
RESTBucks
payment expected preparing cancelled ready completed 1 2 3 4 5 6- rders
- rder
Spring RESTBucks
41- Orders
JacksonCustomizations Externalize tweaks to the general JSON design
43Spring Data REST for the CRUDdy parts.
44ResourceProcessor To conditionally sneak links into the default representation.
45Code
46 Spring RESTBucks - https://github.com/olivergierke/spring-restbucksQuestions?
47