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

REST Beyond the Obvious – API design for ever evolving systems

REST Beyond the Obvious – API design for ever evolving systems

Slides of the talk I held at Spring I/O 2018.

@springcentral

Oliver Drotbohm

May 24, 2018
Tweet

More Decks by Oliver Drotbohm

Other Decks in Programming

Transcript

  1. ARCHITECTURAL CONSTRAINTS TRAITS 5 Evolvability, Scalability, Fault Tolerance, … Client-Server,

    Statelessness, Cacheability, Uniform Interface, Layered System, (Code on Demand…)
  2. 8

  3. 9

  4. 12 CRUD + Validation  Browser Ȑ Application  Database

    {…} JS CRUD Business logic Validation
  5. 14  Browser Ȑ Application  Database {…} JS Mobile

    {…} CRUD CRUD + Validation Business logic Validation
  6. 18

  7. 20

  8. 23

  9. 24 From: Stefan Tilkov – Microservices: Patterns and Antipatterns Data

    Domain Logic CRUD via HTTP / JDBC in disguise Spring Data REST / Re-usable, but low-level
  10. 24 From: Stefan Tilkov – Microservices: Patterns and Antipatterns Data

    Domain Logic Process Flow CRUD via HTTP / JDBC in disguise Spring Data REST / Re-usable, but low-level Useful and specific
  11. 25 Data Domain Logic Process Flow Presentation From: Stefan Tilkov

    – Microservices: Patterns and Antipatterns CRUD via HTTP / JDBC in disguise Spring Data REST / Re-usable, but low-level Useful and specific
  12. 29

  13. 31 class SomeService { UserAccount create(…) { … } }

    class UserAccount {
 Salutation salutation; } enum Salutation { MR, MRS; }
  14. 32 { "type": „object“, "properties": { "salutation": { "type": "array",

    "items": { "type": "string", "enum": ["Mr", "Mrs"] } } } }
  15. class SomeService { UserAccount create(…) { … } } class

    UserAccount {
 Salutation salutation; } enum Salutation { MR, MRS, PROF; } 34
  16. { "type": "object", "properties": { "salutation": { "type": "array", "items":

    { "type": "string", "enum": ["Mr", "Mrs", "Prof"] } } } } 36
  17. 38

  18. 39 Jim Weirich, 2009 – Video @ YouTube The Grand

    Unified Theory Meilir Page-Jones, 2000 – Book @ Amazon Fundamentals of Object-oriented Design in UML
  19. The Cost of Versioning an API 45 From: Jacques Dubray

    - Understanding the cost of versioning an API
  20. 47

  21. 48

  22. 50 payment expected preparing cancelled ready completed 1 2 3

    4 5 6 From: REST In Practice – O'Reilly Sample code @ GitHub: Spring RESTBucks
  23. 51 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
  24. 56

  25. 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 59
  26. 60 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
  27. 61 GET /order/42 { "_links" : { "cancel" : {

    "href" : … }, }, … "createdDate" : …, "status" : "Payment expected", … }
  28. 62

  29. 63

  30. 64 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
  31. 66 Architectural Styles and the Design of Network-based Software Architectures

    Fielding – Dissertation PDF Evolving Distributed Systems Gierke – Blog Microservices: Patterns and Antipatterns Tilkov – Slide deck @ Speakerdeck Fundamentals of Object-oriented Design in UML Meilir Page-Jones, 2000 – Book @ Amazon The Grand Unified Theory Jim Weirich, 2009 – Video @ YouTube
  32. REST In Practice Parastatidis, Webber, Robinson – Book @ O'Reilly

    Spring RESTBucks Drotbohm – Code @ GitHub Spring HATEOAS Project website Spring REST Docs Project website Spring Cloud Contract Project website 67