Building Flexible APIs with Spring HATEOAS

VMware Tanzu
VMware TanzuVMware Tanzu
GregLTurnquist.com/springone2020
Building Flexible APIs
with Spring HATEOAS
September 2–3, 2020
springone.io
1
GregLTurnquist.com/springone2020
Who am I?
GregLTurnquist.com/springone2020
Who am I?
GregLTurnquist.com/springone2020
Who am I?
bit.ly/hacking-with-spring-boot
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
GregLTurnquist.com/springone2020
Let’s talk about…APIs!
GregLTurnquist.com/springone2020
What is an API?
GregLTurnquist.com/springone2020
What is an API?
● Place to get a little JSON/XML/whatever?
GregLTurnquist.com/springone2020
What is an API?
● Place to get a little JSON/XML/whatever?
● Way to interact with the app?
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?
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!
GregLTurnquist.com/springone2020
Simple API
6
● Spring MVC
● Simple
● Clear separation between layers
GregLTurnquist.com/springone2020
Simple API
6
● Spring MVC
● Simple
● Clear separation between layers
GregLTurnquist.com/springone2020
Simple API
6
● Spring MVC
● Simple
● Clear separation between layers
GregLTurnquist.com/springone2020
Simple API
6
● Spring MVC
● Simple
● Clear separation between layers
GregLTurnquist.com/springone2020
Simple API
6
● Spring MVC
● Simple
● Clear separation between layers
GregLTurnquist.com/springone2020
Simple API
{
"id": 0,
"name": "Frodo",
"role": "ring bearer"
}
6
GregLTurnquist.com/springone2020
Simple API
{
"id": 0,
"name": "Frodo",
"role": "ring bearer"
}
6
● Data and…
GregLTurnquist.com/springone2020
Simple API
{
"id": 0,
"name": "Frodo",
"role": "ring bearer"
}
6
● Data and…
● …nothing else!
GregLTurnquist.com/springone2020
Simple API
{
"id": 0,
"name": "Frodo",
"role": "ring bearer"
}
6
● Data and…
● …nothing else!
● Some value, but what about…
GregLTurnquist.com/springone2020
Simple API
{
"id": 0,
"name": "Frodo",
"role": "ring bearer"
}
6
● Data and…
● …nothing else!
● Some value, but what about…
● …updates?
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?
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?
GregLTurnquist.com/springone2020
What happens when…
6
GregLTurnquist.com/springone2020
What happens when…
6
GregLTurnquist.com/springone2020
What happens when you serve this…
{
"id": 0,
"firstName": "Frodo",
"lastName": "Baggins",
"role": "ring bearer"
}
6
GregLTurnquist.com/springone2020
…but older clients try this?
6
GregLTurnquist.com/springone2020
…but older clients try this?
6
● What now?
GregLTurnquist.com/springone2020
…but older clients try this?
6
● What now?
● Tell users to just use your new API?
GregLTurnquist.com/springone2020
…but older clients try this?
6
● What now?
● Tell users to just use your new API?
● Roll out another version?
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?
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
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
“
GregLTurnquist.com/springone2020
How rough can deprecating APIs be?
6
http://bit.ly/deprecating-apis
GregLTurnquist.com/springone2020
Just do this…
6
GregLTurnquist.com/springone2020
Just do this…
6
● “Never delete a
column”
GregLTurnquist.com/springone2020
Just do this…
6
● “Never delete a
column”
● Handle new
clients
GregLTurnquist.com/springone2020
Just do this…
6
● “Never delete a
column”
● Handle new
clients
● Support old
clients
GregLTurnquist.com/springone2020
Just do this…
6
● “Never delete a
column”
● Handle new
clients
● Support old
clients
● Everyone wins!
GregLTurnquist.com/springone2020
What else do you need?
GregLTurnquist.com/springone2020
What else do you need?
● Hypermedia controls
GregLTurnquist.com/springone2020
What else do you need?
● Hypermedia controls
● Instead of telling someone how to use your API on a portal…
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
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
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
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
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
GregLTurnquist.com/springone2020
Just migrate from this…
6
GregLTurnquist.com/springone2020
…to this!
6
GregLTurnquist.com/springone2020
…to this!
6
GregLTurnquist.com/springone2020
…to this!
6
GregLTurnquist.com/springone2020
…to this!
6
GregLTurnquist.com/springone2020
…to this!
6
GregLTurnquist.com/springone2020
…to this!
6
GregLTurnquist.com/springone2020
…to this!
6
GregLTurnquist.com/springone2020
…to this!
6
GregLTurnquist.com/springone2020
…to this!
6
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
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
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
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
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
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!)
GregLTurnquist.com/springone2020
Consuming Hypermedia
GregLTurnquist.com/springone2020
What if…
GregLTurnquist.com/springone2020
What if…
● You wanted your client to consume hypermedia?
GregLTurnquist.com/springone2020
What if…
● You wanted your client to consume hypermedia?
● Ready to register all those messy message converters?
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.?
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.?
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!
GregLTurnquist.com/springone2020
RestTemplate support
GregLTurnquist.com/springone2020
RestTemplate support
GregLTurnquist.com/springone2020
RestTemplate support
GregLTurnquist.com/springone2020
RestTemplate support
GregLTurnquist.com/springone2020
RestTemplate support
GregLTurnquist.com/springone2020
We also support WebClient
● Inject WebClient.Builder into your app
● …and .build()!
GregLTurnquist.com/springone2020
We also support WebClient
● Inject WebClient.Builder into your app
● …and .build()!
GregLTurnquist.com/springone2020
We also support WebClient
GregLTurnquist.com/springone2020
We also support WebClient
GregLTurnquist.com/springone2020
We also support WebClient
GregLTurnquist.com/springone2020
We also support WebClient
😳Not in production!
GregLTurnquist.com/springone2020
Additional Features
GregLTurnquist.com/springone2020
Additional Features
● Spring WebFlux support
GregLTurnquist.com/springone2020
Additional Features
● Spring WebFlux support
● More media types (UBER+JSON, Collection+JSON, Your Own ™)
GregLTurnquist.com/springone2020
Additional Features
● Spring WebFlux support
● More media types (UBER+JSON, Collection+JSON, Your Own ™)
● Standardized errors with Problem+JSON (RFC-7807)
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
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!
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!
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!
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!
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
1 of 91

More Related Content

What's hot(20)

802.1x802.1x
802.1x
akruthi k2.5K views
Radius1Radius1
Radius1
balamurugan.k Kalibalamurugan675 views
User id installation and configurationUser id installation and configuration
User id installation and configuration
Alberto Rivai14.8K views
RbacRbac
Rbac
أحلام انصارى2.4K views
Role-Based Access ControlRole-Based Access Control
Role-Based Access Control
EmpowerID1.8K views
Basics of sslBasics of ssl
Basics of ssl
n|u - The Open Security Community2.6K views
Authentication methodsAuthentication methods
Authentication methods
sana mateen746 views
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - Introduction
Knoldus Inc.6.2K views
AAA serverAAA server
AAA server
hetvi naik350 views
Types of VPNTypes of VPN
Types of VPN
NetProtocol Xpert1.1K views
OAuth2 and Spring SecurityOAuth2 and Spring Security
OAuth2 and Spring Security
Orest Ivasiv8.5K views
Web-App Remote Code Execution Via Scripting EnginesWeb-App Remote Code Execution Via Scripting Engines
Web-App Remote Code Execution Via Scripting Engines
c0c0n - International Cyber Security and Policing Conference5K views
Broken access controlsBroken access controls
Broken access controls
Akansha Kesharwani1.8K views
Introduction to HTTP protocolIntroduction to HTTP protocol
Introduction to HTTP protocol
Aviran Mordo20.8K views
Click jackingClick jacking
Click jacking
Ronan Dunne, CEH, SSCP10.5K views

Similar to Building Flexible APIs with Spring HATEOAS(20)

Building Flexible APIs with Spring HATEOAS