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

Spring RESTBucks - A Hypermedia REST Web Service

Oliver Drotbohm
September 10, 2013

Spring RESTBucks - A Hypermedia REST Web Service

Oliver Drotbohm

September 10, 2013
Tweet

More Decks by Oliver Drotbohm

Other Decks in Programming

Transcript

  1. © 2013 SpringOne 2GX. All rights reserved. Do not distribute

    without permission. A hypermedia-driven REST web service Oliver Gierke Spring RESTBucks
  2. Oliver Gierke Spring Data engineer Core / JPA / Mongo

    JPA Expert Group [email protected] www.olivergierke.de olivergierke
  3. Spring Data Modern Data Access For Enterprise Java NoSQL JPA

    JDBC Redis Big Data Hadoop HBase MongoDB Neo4j REST exporter Roo Hive Pig Querydsl Repositories Gemfire Splunk Free e-book for every attendee!
  4. Technologies Spring Framework (4.0 M3) Spring Data JPA (1.4.1 /

    Babbage) Spring Data REST (2.0 snapshots) Spring HATEOAS (0.8)
  5. Web Service Repository - Orders Spring Data Spring Data REST

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

    Payment Spring Data Manual implementation Manual implementation
  7. Lab

  8. Lab Setup Spring through JavaConfig Setup JPA in Spring context

    Enable Spring Data JPA Write integration tests for data access
  9. Lab

  10. Lab Setup Servlet 3.0 web app with Spring Activate Spring

    Data REST Spring MVC integration test setup Write web integration tests
  11. Method URI Action Step POST /orders Create new order 1

    POST/PATCH /orders/4711 Update the order (only if "payment expected") 2 DELETE /orders/4711 Cancel order (only if "payment expected") 3 PUT /orders/4711/payment Pay order 4 Barista preparing the order Barista preparing the order Barista preparing the order Barista preparing the order GET /orders/4711 Poll order state 5 GET /orders/4711/receipt Access receipt DELETE /orders/4711/receipt Conclude the order process 6
  12. orders Returns all orders available in the system order Returns

    a single order self The uri value can be used to GET the latest resource representation of the order. cancel This is the URI to be used to DELETE the order resource should the consumer wish to cancel the order. update Consumers can change the order using a POST to transfer a representation to the linked resource. payment The linked resource allows the consumer to begin paying for an order. Initiating payment involves PUTting an appropriate resource representation to the specified URI. receipt The URI to access the receipt using GET and conclude the order by taking the receipt (use DELETE).
  13. orders Returns all orders available in the system order Returns

    a single order self The uri value can be used to GET the latest resource representation of the order. cancel This is the URI to be used to DELETE the order resource should the consumer wish to cancel the order. update Consumers can change the order using a POST to transfer a representation to the linked resource. payment The linked resource allows the consumer to begin paying for an order. Initiating payment involves PUTting an appropriate resource representation to the specified URI. receipt The URI to access the receipt using GET and conclude the order by taking the receipt (use DELETE).
  14. Method URI Action Step POST /orders Create new order 1

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

    1 POST/PATCH update Update the order (only if "payment expected") 2 DELETE cancel Cancel order (only if "payment expected") 3 PUT payment Pay order 4 Barista preparing the order Barista preparing the order Barista preparing the order Barista preparing the order GET order Poll order state 5 GET receipt Access receipt DELETE receipt Conclude the order process 6
  16. { links : [ { rel : "self", href :

    … }, { rel : "cancel", href : … }, { rel : "update", href : … }, { rel : "payment", href : "…/orders/4711/payment" } ], content : { items : [ { drink : "Cappucino", size : "large", milk : "semi" price : 4.2 } ], location : "take-away", price : 4.2 status : "payment expected" } }
  17. { links : [ { rel : "self", href :

    "…/orders/4711" }, … { rel : "payment", href : "…/orders/4711/payment" } ], content : { items : [ { drink : "Cappucino", size : "large", milk : "semi" price : 4.2 } ], location : "take-away", price : 4.2 status : "payment expected" } }
  18. { links : [ { rel : "self", href :

    "…/orders/4711/payment" }, { rel : "order", href : "…/orders/4711" } ], content : { creditCard : [ { number : "1234123412341234", cardHolder : "Oliver Gierke", expiryDate : "2013-11-01" } ], amount : { currency : "EUR", value : 4.2 } } }
  19. { links : [ { rel : "self", href :

    "…/orders/4711/payment" }, { rel : "order", href : "…/orders/4711" } ], content : { creditCard : [ { number : "1234123412341234", cardHolder : "Oliver Gierke", expiryDate : "2013-11-01" } ], amount : { currency : "EUR", value : 4.2 } } }
  20. { links : [ { rel : "self", href :

    "…/orders/4711" } ], content : { items : [ { drink : "Cappucino", size : "large", milk : "semi" price : 4.2 } ], location : "take-away", price : 4.2 status : "preparing" } }
  21. { links : [ { rel : "self", href :

    "…/orders/4711" }, { rel : "receipt", href : "…/orders/4711/receipt" } ], content : { items : [ { drink : "Cappucino", size : "large", milk : "semi" price : 4.2 } ], location : "take-away", price : 4.2 status : "ready" } }
  22. { links : [ { rel : "self", href :

    "…/orders/4711" }, { rel : "receipt", href : "…/orders/4711/receipt" } ], content : { items : [ { drink : "Cappucino", size : "large", milk : "semi" price : 4.2 } ], location : "take-away", price : 4.2 status : "ready" } }
  23. Spring Data REST Exports JPA repositories as resources Hypermedia driven

    representations Extension points http://bit.ly/sd-rest
  24. Further talks Spring Data Repositories - Best practices - Wed

    10:30am Multi Client Development with Spring - Wed 4:30pm