Slide 1

Slide 1 text

GregLTurnquist.com/springone2020 Building Flexible APIs with Spring HATEOAS September 2–3, 2020 springone.io 1

Slide 2

Slide 2 text

GregLTurnquist.com/springone2020 Who am I?

Slide 3

Slide 3 text

GregLTurnquist.com/springone2020 Who am I?

Slide 4

Slide 4 text

GregLTurnquist.com/springone2020 Who am I? bit.ly/hacking-with-spring-boot

Slide 5

Slide 5 text

GregLTurnquist.com/springone2020 Who am I? bit.ly/hacking-with-spring-boot ● Principal developer on the Spring team ● Nashville JUG co-founder ● Committer & Project Lead for several Spring projects ● YouTube/GregTurnquist

Slide 6

Slide 6 text

GregLTurnquist.com/springone2020 Let’s talk about…APIs!

Slide 7

Slide 7 text

GregLTurnquist.com/springone2020 What is an API?

Slide 8

Slide 8 text

GregLTurnquist.com/springone2020 What is an API? ● Place to get a little JSON/XML/whatever?

Slide 9

Slide 9 text

GregLTurnquist.com/springone2020 What is an API? ● Place to get a little JSON/XML/whatever? ● Way to interact with the app?

Slide 10

Slide 10 text

GregLTurnquist.com/springone2020 What is an API? ● Place to get a little JSON/XML/whatever? ● Way to interact with the app? ● Means to extract value from another app to help your own app?

Slide 11

Slide 11 text

GregLTurnquist.com/springone2020 What is an API? ● Place to get a little JSON/XML/whatever? ● Way to interact with the app? ● Means to extract value from another app to help your own app? Let’s dig in and discover what it means to have a flexible API!

Slide 12

Slide 12 text

GregLTurnquist.com/springone2020 Simple API 6 ● Spring MVC ● Simple ● Clear separation between layers

Slide 13

Slide 13 text

GregLTurnquist.com/springone2020 Simple API 6 ● Spring MVC ● Simple ● Clear separation between layers

Slide 14

Slide 14 text

GregLTurnquist.com/springone2020 Simple API 6 ● Spring MVC ● Simple ● Clear separation between layers

Slide 15

Slide 15 text

GregLTurnquist.com/springone2020 Simple API 6 ● Spring MVC ● Simple ● Clear separation between layers

Slide 16

Slide 16 text

GregLTurnquist.com/springone2020 Simple API 6 ● Spring MVC ● Simple ● Clear separation between layers

Slide 17

Slide 17 text

GregLTurnquist.com/springone2020 Simple API { "id": 0, "name": "Frodo", "role": "ring bearer" } 6

Slide 18

Slide 18 text

GregLTurnquist.com/springone2020 Simple API { "id": 0, "name": "Frodo", "role": "ring bearer" } 6 ● Data and…

Slide 19

Slide 19 text

GregLTurnquist.com/springone2020 Simple API { "id": 0, "name": "Frodo", "role": "ring bearer" } 6 ● Data and… ● …nothing else!

Slide 20

Slide 20 text

GregLTurnquist.com/springone2020 Simple API { "id": 0, "name": "Frodo", "role": "ring bearer" } 6 ● Data and… ● …nothing else! ● Some value, but what about…

Slide 21

Slide 21 text

GregLTurnquist.com/springone2020 Simple API { "id": 0, "name": "Frodo", "role": "ring bearer" } 6 ● Data and… ● …nothing else! ● Some value, but what about… ● …updates?

Slide 22

Slide 22 text

GregLTurnquist.com/springone2020 Simple API { "id": 0, "name": "Frodo", "role": "ring bearer" } 6 ● Data and… ● …nothing else! ● Some value, but what about… ● …updates? ● …breaking changes?

Slide 23

Slide 23 text

GregLTurnquist.com/springone2020 Simple API { "id": 0, "name": "Frodo", "role": "ring bearer" } 6 ● Data and… ● …nothing else! ● Some value, but what about… ● …updates? ● …breaking changes? ● …backwards compatibility?

Slide 24

Slide 24 text

GregLTurnquist.com/springone2020 What happens when… 6

Slide 25

Slide 25 text

GregLTurnquist.com/springone2020 What happens when… 6

Slide 26

Slide 26 text

GregLTurnquist.com/springone2020 What happens when you serve this… { "id": 0, "firstName": "Frodo", "lastName": "Baggins", "role": "ring bearer" } 6

Slide 27

Slide 27 text

GregLTurnquist.com/springone2020 …but older clients try this? 6

Slide 28

Slide 28 text

GregLTurnquist.com/springone2020 …but older clients try this? 6 ● What now?

Slide 29

Slide 29 text

GregLTurnquist.com/springone2020 …but older clients try this? 6 ● What now? ● Tell users to just use your new API?

Slide 30

Slide 30 text

GregLTurnquist.com/springone2020 …but older clients try this? 6 ● What now? ● Tell users to just use your new API? ● Roll out another version?

Slide 31

Slide 31 text

GregLTurnquist.com/springone2020 …but older clients try this? 6 ● What now? ● Tell users to just use your new API? ● Roll out another version? ● Handle this AND the new format?

Slide 32

Slide 32 text

GregLTurnquist.com/springone2020 What about versioning? 6 https://www.infoq.com/news/2013/12/api-versioning/ ● Knot = Single version of API ● P2P = Multiple versions ● Compatible = One API supports multiple versions

Slide 33

Slide 33 text

GregLTurnquist.com/springone2020 What about versioning? 6 It is always possible for some unexpected reason to come along that requires a completely different API, especially when the semantics of the interface change or security issues require the abandonment of previously deployed software. My point was that there is no need to anticipate such world-breaking changes with a version ID. We have the hostname for that. What you are creating is not a new version of the API, but a new system with a new brand. On the Web, we call that a new website. Websites don’t come with version numbers attached because they never need to. Neither should a RESTful API. A RESTful API (done right) is just a website for clients with a limited vocabulary. —Dr. Roy Fielding “

Slide 34

Slide 34 text

GregLTurnquist.com/springone2020 How rough can deprecating APIs be? 6 http://bit.ly/deprecating-apis

Slide 35

Slide 35 text

GregLTurnquist.com/springone2020 Just do this… 6

Slide 36

Slide 36 text

GregLTurnquist.com/springone2020 Just do this… 6 ● “Never delete a column”

Slide 37

Slide 37 text

GregLTurnquist.com/springone2020 Just do this… 6 ● “Never delete a column” ● Handle new clients

Slide 38

Slide 38 text

GregLTurnquist.com/springone2020 Just do this… 6 ● “Never delete a column” ● Handle new clients ● Support old clients

Slide 39

Slide 39 text

GregLTurnquist.com/springone2020 Just do this… 6 ● “Never delete a column” ● Handle new clients ● Support old clients ● Everyone wins!

Slide 40

Slide 40 text

GregLTurnquist.com/springone2020 What else do you need?

Slide 41

Slide 41 text

GregLTurnquist.com/springone2020 What else do you need? ● Hypermedia controls

Slide 42

Slide 42 text

GregLTurnquist.com/springone2020 What else do you need? ● Hypermedia controls ● Instead of telling someone how to use your API on a portal…

Slide 43

Slide 43 text

GregLTurnquist.com/springone2020 What else do you need? ● Hypermedia controls ● Instead of telling someone how to use your API on a portal… ● …give them the controls right in the API

Slide 44

Slide 44 text

GregLTurnquist.com/springone2020 What else do you need? ● Hypermedia controls ● Instead of telling someone how to use your API on a portal… ● …give them the controls right in the API ● …using standard media types

Slide 45

Slide 45 text

GregLTurnquist.com/springone2020 What else do you need? ● Hypermedia controls ● Instead of telling someone how to use your API on a portal… ● …give them the controls right in the API ● …using standard media types ● It’s how the web functions

Slide 46

Slide 46 text

GregLTurnquist.com/springone2020 What else do you need? ● Hypermedia controls ● Instead of telling someone how to use your API on a portal… ● …give them the controls right in the API ● …using standard media types ● It’s how the web functions ● It’s the reason the web succeeded

Slide 47

Slide 47 text

GregLTurnquist.com/springone2020 What else do you need? ● Hypermedia controls ● Instead of telling someone how to use your API on a portal… ● …give them the controls right in the API ● …using standard media types ● It’s how the web functions ● It’s the reason the web succeeded ● The reason everyone today builds web apps

Slide 48

Slide 48 text

GregLTurnquist.com/springone2020 Just migrate from this… 6

Slide 49

Slide 49 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 50

Slide 50 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 51

Slide 51 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 52

Slide 52 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 53

Slide 53 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 54

Slide 54 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 55

Slide 55 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 56

Slide 56 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 57

Slide 57 text

GregLTurnquist.com/springone2020 …to this! 6

Slide 58

Slide 58 text

GregLTurnquist.com/springone2020 { "id": 0, "firstName": "Frodo", "lastName": "Baggins", "role": "ring bearer", "name": "Frodo Baggins", "_links": { "self": { "href": "http://localhost:8080/rest/employees/0" }, "employees": { "href": "http://localhost:8080/rest/employees" } }, … So you can do this! 6 ● New clients

Slide 59

Slide 59 text

GregLTurnquist.com/springone2020 { "id": 0, "firstName": "Frodo", "lastName": "Baggins", "role": "ring bearer", "name": "Frodo Baggins", "_links": { "self": { "href": "http://localhost:8080/rest/employees/0" }, "employees": { "href": "http://localhost:8080/rest/employees" } }, … So you can do this! 6 ● New clients ● Old clients

Slide 60

Slide 60 text

GregLTurnquist.com/springone2020 { "id": 0, "firstName": "Frodo", "lastName": "Baggins", "role": "ring bearer", "name": "Frodo Baggins", "_links": { "self": { "href": "http://localhost:8080/rest/employees/0" }, "employees": { "href": "http://localhost:8080/rest/employees" } }, … So you can do this! 6 ● New clients ● Old clients ● Navigate between related components

Slide 61

Slide 61 text

GregLTurnquist.com/springone2020 …and this 6 … "_templates": { "default": { "method": "put", "properties": [ { "name": "firstName" }, { "name": "id", "readOnly": true }, { "name": "lastName" }, { "name": "name" }, { "name": "role" } ]}}} ● New clients ● Old clients ● Navigate between related components ● Effect change

Slide 62

Slide 62 text

GregLTurnquist.com/springone2020 … "_templates": { "default": { "method": "put", "properties": [ { "name": "firstName" }, { "name": "id", "readOnly": true }, { "name": "lastName" }, { "name": "name" }, { "name": "role" } ]}}} …and this 6 ● New clients ● Old clients ● Navigate between related components ● Effect change

Slide 63

Slide 63 text

GregLTurnquist.com/springone2020 … "_templates": { "default": { "method": "put", "properties": [ { "name": "firstName" }, { "name": "id", "readOnly": true }, { "name": "lastName" }, { "name": "name" }, { "name": "role" } ]}}} …and this 6 ● New clients ● Old clients ● Navigate between related components ● Effect change (even for old clients!)

Slide 64

Slide 64 text

GregLTurnquist.com/springone2020 Consuming Hypermedia

Slide 65

Slide 65 text

GregLTurnquist.com/springone2020 What if…

Slide 66

Slide 66 text

GregLTurnquist.com/springone2020 What if… ● You wanted your client to consume hypermedia?

Slide 67

Slide 67 text

GregLTurnquist.com/springone2020 What if… ● You wanted your client to consume hypermedia? ● Ready to register all those messy message converters?

Slide 68

Slide 68 text

GregLTurnquist.com/springone2020 What if… ● You wanted your client to consume hypermedia? ● Ready to register all those messy message converters? ● Do you really want to look up how to customize RestTemplate (or WebClient) to handle HAL, HAL-FORMS, etc., etc., etc.?

Slide 69

Slide 69 text

GregLTurnquist.com/springone2020 What if… ● You wanted your client to consume hypermedia? ● Ready to register all those messy message converters? ● Do you really want to look up how to customize RestTemplate (or WebClient) to handle HAL, HAL-FORMS, etc., etc., etc.?

Slide 70

Slide 70 text

GregLTurnquist.com/springone2020 What if… ● You wanted your client to consume hypermedia? ● Ready to register all those messy message converters? ● Do you really want to look up how to customize RestTemplate (or WebClient) to handle HAL, HAL-FORMS, etc., etc., etc.? Spring HATEOAS has you covered!

Slide 71

Slide 71 text

GregLTurnquist.com/springone2020 RestTemplate support

Slide 72

Slide 72 text

GregLTurnquist.com/springone2020 RestTemplate support

Slide 73

Slide 73 text

GregLTurnquist.com/springone2020 RestTemplate support

Slide 74

Slide 74 text

GregLTurnquist.com/springone2020 RestTemplate support

Slide 75

Slide 75 text

GregLTurnquist.com/springone2020 RestTemplate support

Slide 76

Slide 76 text

GregLTurnquist.com/springone2020 We also support WebClient ● Inject WebClient.Builder into your app ● …and .build()!

Slide 77

Slide 77 text

GregLTurnquist.com/springone2020 We also support WebClient ● Inject WebClient.Builder into your app ● …and .build()!

Slide 78

Slide 78 text

GregLTurnquist.com/springone2020 We also support WebClient

Slide 79

Slide 79 text

GregLTurnquist.com/springone2020 We also support WebClient

Slide 80

Slide 80 text

GregLTurnquist.com/springone2020 We also support WebClient

Slide 81

Slide 81 text

GregLTurnquist.com/springone2020 We also support WebClient Not in production!

Slide 82

Slide 82 text

GregLTurnquist.com/springone2020 Additional Features

Slide 83

Slide 83 text

GregLTurnquist.com/springone2020 Additional Features ● Spring WebFlux support

Slide 84

Slide 84 text

GregLTurnquist.com/springone2020 Additional Features ● Spring WebFlux support ● More media types (UBER+JSON, Collection+JSON, Your Own ™)

Slide 85

Slide 85 text

GregLTurnquist.com/springone2020 Additional Features ● Spring WebFlux support ● More media types (UBER+JSON, Collection+JSON, Your Own ™) ● Standardized errors with Problem+JSON (RFC-7807)

Slide 86

Slide 86 text

GregLTurnquist.com/springone2020 Additional Features ● Spring WebFlux support ● More media types (UBER+JSON, Collection+JSON, Your Own ™) ● Standardized errors with Problem+JSON (RFC-7807) ● Lots of performance improvements

Slide 87

Slide 87 text

GregLTurnquist.com/springone2020 Additional Features ● Spring WebFlux support ● More media types (UBER+JSON, Collection+JSON, Your Own ™) ● Standardized errors with Problem+JSON (RFC-7807) ● Lots of performance improvements ● Increasing community involvement ● JSON:API, Siren media types ● Document updates ● New ideas!

Slide 88

Slide 88 text

GregLTurnquist.com/springone2020 Additional Features ● Spring WebFlux support ● More media types (UBER+JSON, Collection+JSON, Your Own ™) ● Standardized errors with Problem+JSON (RFC-7807) ● Lots of performance improvements ● Increasing community involvement ● JSON:API, Siren media types ● Document updates ● New ideas!

Slide 89

Slide 89 text

GregLTurnquist.com/springone2020 Additional Features ● Spring WebFlux support ● More media types (UBER+JSON, Collection+JSON, Your Own ™) ● Standardized errors with Problem+JSON (RFC-7807) ● Lots of performance improvements ● Increasing community involvement ● JSON:API, Siren media types ● Document updates ● New ideas!

Slide 90

Slide 90 text

GregLTurnquist.com/springone2020 Additional Features ● Spring WebFlux support ● More media types (UBER+JSON, Collection+JSON, Your Own ™) ● Standardized errors with Problem+JSON (RFC-7807) ● Lots of performance improvements ● Increasing community involvement ● JSON:API, Siren media types ● Document updates ● New ideas! Check it out!

Slide 91

Slide 91 text

GregLTurnquist.com/springone2020 Thank you SpringOne 2020! Join me on #session-building-flexible-apis-with-spring-hateoas for Q&A Follow us on twitter @SpringHATEOAS Visit GregLTurnquist.com/springone2020 to WIN a paperback+ebook copy of Hacking with Spring Boot 2.3