what needs to be done to make the rest architectural
play

" What needs to be done to make the REST architectural style - PowerPoint PPT Presentation

" What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint? In other words, if the engine of application state (and hence the API) is not being driven by hypertext, then it cannot


  1. 
 " What needs to be done to make the REST architectural style clear on the notion that hypertext is a constraint? In other words, if the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. Period. Is there some broken manual somewhere that needs to be fixed? 
 – Roy T. Fielding

  2. REST Assured Hypermedia APIs with Spring � � Oliver Gierke

  3. Oliver Gierke Engineer @ Pivotal Spring Data project lead � ogierke@gopivotal.com www.olivergierke.de olivergierke

  4. Background

  5. REST

  6. REST Resources URIs Uniform Interface Representations

  7. Hypermedia

  8. " HATEOAS - the word, there's no pronunciation for. � – Ben Hale (SpringOne2GX 2012)

  9. Hypermedia Links in representations State navigations discoverable

  10. { _links : { self : { href : … }, cancel : { href : … }, update : { href : … }, payment : { href : "…/orders/4711/payment" } }, � items : [ { … } ], � location : "take-away", price : 4.2, status : "payment expected" }

  11. MediaType text/html application/hal+(json|xml) application/collection+json

  12. Implementation aspects

  13. Hypermedia VS. Java Frameworks

  14. Spring MVC JAX-RS ✓ ✓ HTTP Methods ✓ ✓ URI Mapping Content 
 ✓ ✓ negotiation Hypermedia ? ?

  15. Spring HATEOAS

  16. Spring HATEOAS Representation models LinkBuilder API Representation enrichment http:/ /bit.ly/spring-hateoas

  17. DEMO https:/ /github.com/olivergierke/spring- hateoas-sample

  18. Spring Data REST

  19. Spring Data REST Export Spring Data repositories in a hypermedia-driven way Do „the right thing™“ by default

  20. DEMO https:/ /github.com/olivergierke/rest- microservices

  21. REST in practice

  22. RESTBucks

  23. RESTBucks Starbucks (like) co ff ee ordering Order / Payment

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

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

  26. Challenges

  27. Challenges How to avoid hard coding URIs?

  28. Use link relations

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

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

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

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

  33. Challenges How to implement: 
 "only if payment expected“? � Clients react on the presence of links

  34. Spring RESTBucks

  35. Spring RESTBucks Sample implementation Using Spring technologies http:/ /bit.ly/spring-restbucks

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

  37. DEMO https:/ /github.com/olivergierke/spring- restbucks

  38. API docs?

  39. " How does the client make sense of all this?

  40. Profiles

  41. Profiles RFC 6906 Points to resources describing additional semantics within a media type

  42. Curies

  43. (HAL) Curies

  44. { "_links" : { "self" : { "href" : … }, "restbucks:cancel" : { "href" : … }, "restbucks:update" : { "href" : … }, � "curies" : { "name" : "restbucks", "href" : "…/rels/{rel}" "templated" : true } }, … } Docs for update are at: …/rels/update

  45. alps.io

  46. alps.io Application Level Profile Semantics Describe state transitions and payloads Media type agnostic Repository with pre-defined docs application/alps+(json|xml)

  47. DEMO

  48. Miscellaneous Spring MVC integration testing REST Shell

  49. Thank you!

  50. Resources

  51. Code Spring HATEOAS Sample REST micro-services Spring RESTBucks

  52. Books RESTful Web APIs REST in Practice REST und HTTP

  53. Videos Hypermedia APIs - Jon Moore Hypermedia APIs with Spring

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