DDD & REST Domain Driven Apis for the Web
-
Upload
spring-by-pivotal -
Category
Technology
-
view
2.309 -
download
3
Transcript of DDD & REST Domain Driven Apis for the Web
Unless o therw ise ind ica ted , these s l ides are © 2013-2016 P ivo ta l So f tware , Inc . and l i censed under a Creat ive Commons At t r ibu t ion-NonCommerc ia l l i cense: h t tp : / / c rea t ivecommons.org / l i censes /by-nc /3 .0 /
DDD & RESTDomain-Driven APIs for the web
Oliver Gierke !/" olivergierke
8
http://www.infoq.com/minibooks/domain-driven-design-quickly
Stringly typed code12
public class Customer {
private Long id;private String firstname, lastname, email;
…}
Stringly typed code13
public class SomeService {
public void createUser(String firstname, String lastname, String email) {
…}
}
14
public class Customer {
private Long id;private Firstname firstname;private Lastname lastname;private EmailAddress emailAddress;
…}
Still, they’re worth it.
16
See „Power Use of Value Objects in DDD“ by Dan Bergh Johnsson.
18
@Valuepublic class Customer {
UUID id = UUID.randomUUID();Firstname firstname;Lastname lastname;EmailAddress email;
@Valuestatic class EmailAddress {String value;
}}
AutoValue
19
Project website on GitHub.
31
Shipping
AccountingCatalog
Orders
UserRegistration
Accounting Payment information
Billing Address
Shipping
Shipping address
Customer
31
Shipping
AccountingCatalog
Orders
UserRegistration
Accounting Payment information
Billing Address
Shipping
Shipping address
Customer
Product
38
Level 0: No events at all
Level 1: Explicit operations
Level 2: Some operations as events
Level 3: Event Sourcing
48
Amount of domain knowledge in the client
Amount of protocol knowledge in the client
Coupling to the server
Non-hypermediabased systems
Hypermediabased systems
50
GET /orders
{ „_links“ : { „cancel“ : { „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
51
GET /orders
{ „_links“ : { „cancel“ : { „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
54
GET /orders
{ „_links“ : { „cancel“ : { „href“ : … }, … „createdDate“ : …, „status“ : „Payment expected“ … }
58
Aggregate Root / Repository
Collection / Item Resources
IDs URIs
@Version ETags
Last Modified Property
Last Modified Header
Relations Links
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
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
Web
Service
Repository
-
Orders
Spring Data
Spring DataREST
Payment
Spring Data
Manualimplementation
Manualimplementation
Resources
67
Spring RESTBuckshttps://github.com/olivergierke/spring-restbucks
Benefits of Hypermedia APIshttp://olivergierke.de/2016/04/benefits-of-hypermedia/index.html