SlideShare una empresa de Scribd logo
1 de 64
Hypermedia-driven
Web Services
with
Spring Data REST
1
Sofiia Vynnytska
2
Agenda
• HATEOAS
• Spring Data REST
• Demos
3
44
supershirtguy.com/Funny-T-Shirts/Old%20School%20Homer%20Shirt%20Grey.php
Classic way
Controller Service Repository Database
5
Simple Junior Engineers API
• Create
• Update
• Delete
• Get by Id
• Get all
6
https://www.uvu.edu
DEMO TIME!
7
Pros and Cons
+ We know how it works
+ Everything is clear
+ Easy to debug
- A lot of code for simple API
- Code duplication
- No business logic
8
stockfresh.com
Client Server
Communication
9
says they want something called service.
10
Someone calling themselves a client
www.newslettercartoons.com
11
[{
"id": "1",
"firstName": "Evgeny",
"lastName": "Borisov"
},
{
"id": "2",
"firstName": "Mikalai",
"lastName ": "Alimenkou"
}]
"/juniors"
12
"/juniors" + "/1"
"/engineers/1" + "/skill?newSkill=" + "Java 9"
{
"id": "1",
"firstName": "Evgeny",
"lastName": "Borisov",
"skills": ["Spring", "Spring Boot"]
}
13
memegenerator.net
14
www.business2community.com
HATEOAS
15
WELL GIRL…
WAIT WHAT DID YOU JUST SAY?16
http://www.express.co.uk/
I HATE
OARS 17
18
Hypermedia
As
The
Engine
Of
Application
State
19
{
"id": "1",
"fullName": "Evgeny Borisov",
"skills": ["Spring", "Spring Boot"]
"_links": {
"self": {
"href":"http://localhost:8080/juniors/1"
},
"add-java-9": {
"href":"http://localhost:8080/juniors/1
/skill?newSkill=Java 9"
}
}
}
Pros and Cons
+ Discoverability
+ It’s all about server
+ No client knowledge
- Complex
- Learning curve
stockfresh.com 20
21
http://www.thesimpleway.org/
Spring Data REST
22
It’s REST time 23
Spring Data REST
Spring Data
REST API
Implementation
Spring Data
REST
24
Support
DATA
25
Spring Data REST
@RepositoryRestResource
public interface JuniorEngineerRepository
extends CrudRepository<JuniorEngineer, String> {
}
26
Repository detection
27
biwizard.wordpress.com/
Repository detection strategy
• Default
• Annotation
28
• Visibility
• All
Repository detection strategy
spring.data.rest.detection-strategy=annotated
29
Hiding repository and methods
@RepositoryRestResource(exported = false)
public interface JuniorEngineerRepository
extends CrudRepository<JuniorEngineer, String>{
@RestResource(exported = false)
void delete(String id);
}
30
Resources
31
Resource path
@RepositoryRestResource
public interface JuniorEngineerRepository
extends CrudRepository<JuniorEngineer, String>{
}
32
"/juniorEngineers"
(path = "juniors")
Collection resource
33
Collection resource
GET
34
"/juniors"
POST
findAll()
save(…)
Item resource
35
Item resource
36
"/juniors/{id}"
GET
PUT
PATCH
DELETE
findOne(…)
save (…)
save (…)
delete(…)
Search resource
37
38
May I have a cigarette
or should I search for it?
Search resource
39
@RepositoryRestResource(path = "juniors")
public interface JuniorEngineerRepository
extends CrudRepository<JuniorEngineer, String>{
@RestResource
List<JuniorEngineer> findByProjectIsNull();
}
Search resource
40
"/juniors/search"
"/juniors/search/findByProjectIsNull"
41lh5.googleusercontent.com/-rcOOyxZszOw/VIdTCBTMHeI/AAAAAAAACp4/Z9QR4R1C89M/template-minion2.gif
Client specific
representations
42
43
www.elitereaders.com
Projections
44
Projections
@Projection(types = JuniorEngineer.class, name = "minimal")
public interface MinimalProjection {
Set<String> getSkills();
@Value("#{target.firstName} #{target.lastName}")
String getFullName();
}
45
Projections discovery
• Same package as domain
• Register manually
RepositoryRestConfiguration
.getProjectionConfiguration()
.addProjection(…)
46
Excerpts
47
48
Excerpts
@RepositoryRestResource(excerptProjection = DefaultProjection.class)
• Collection
• No item
49
DEMO TIME!
50https://movies.alphacoders.com/movies/view/28/The-Matrix
Validation
51
ratiocinativa.files.wordpress.com
Validation
● Bind it by name
@Component("beforeCreateSeniorValidator")
public class SeniorValidator implements Validator {…}
● Register manually
ValidatingRepositoryEventListener
.addValidator("beforeCreate", new SeniorValidator());
52
DEMO
53
TIME
giphy.gif
Links
54
Links
• new Link("localhost:8080/juniors", "juniors");
• ControllerLinkBuilder linkTo(), methodOn()
• RepositoryEntityLinks
55
DEMO TIME!
56
Summary
57
Pros and Cons
+ Helps to start quickly
+ CRUD
+ Projections
+ Hypermedia
- Debugging
- Bugs
- No Bean Validation(JSR-303)
58stockfresh.com
When not use Spring Data REST
• Spring, Spring Data in your project
• To much business logic
59
Summary
• REST API
• Projections
• Validation
• Links
60
Useful links
Spring Data REST Docs
Understanding HATEOAS
Projection representation of single resource
Custom methods validation
61
https://github.com/VynnytskaSofiia/demo-
spring-data-rest
62
https://www.facebook.com/sofiia.vynnytska
63cdn2.content.compendiumblog.com
64
ww.pngall.com

Más contenido relacionado

La actualidad más candente

A Modest Introduction To Swift
A Modest Introduction To SwiftA Modest Introduction To Swift
A Modest Introduction To Swift
John Anderson
 

La actualidad más candente (20)

The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
Access Control for HTTP Operations on Linked Data
Access Control for HTTP Operations on Linked DataAccess Control for HTTP Operations on Linked Data
Access Control for HTTP Operations on Linked Data
 
Internal Hive
Internal HiveInternal Hive
Internal Hive
 
A Modest Introduction To Swift
A Modest Introduction To SwiftA Modest Introduction To Swift
A Modest Introduction To Swift
 
Getting Started with Real-Time Analytics
Getting Started with Real-Time AnalyticsGetting Started with Real-Time Analytics
Getting Started with Real-Time Analytics
 
Proper logging can catch breaches like retail PoS
Proper logging can catch breaches like retail PoSProper logging can catch breaches like retail PoS
Proper logging can catch breaches like retail PoS
 
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech TalkHacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
 
Logging for Hackers - What you need to know to catch them
Logging for Hackers - What you need to know to catch themLogging for Hackers - What you need to know to catch them
Logging for Hackers - What you need to know to catch them
 
Admins: Smoke Test Your Hadoop Cluster!
Admins: Smoke Test Your Hadoop Cluster!Admins: Smoke Test Your Hadoop Cluster!
Admins: Smoke Test Your Hadoop Cluster!
 
BSidesOK_You_CAN_detect_PowerShell_attacks_v1.1
BSidesOK_You_CAN_detect_PowerShell_attacks_v1.1BSidesOK_You_CAN_detect_PowerShell_attacks_v1.1
BSidesOK_You_CAN_detect_PowerShell_attacks_v1.1
 
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShellPesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
PesterSec: Using Pester & ScriptAnalyzer to Detect Obfuscated PowerShell
 
Code Reactions - An Introduction to Reactive Extensions
Code Reactions - An Introduction to Reactive ExtensionsCode Reactions - An Introduction to Reactive Extensions
Code Reactions - An Introduction to Reactive Extensions
 
Malware Management - HouSecCon 2014
Malware Management - HouSecCon 2014Malware Management - HouSecCon 2014
Malware Management - HouSecCon 2014
 
Functional tests with TYPO3
Functional tests with TYPO3Functional tests with TYPO3
Functional tests with TYPO3
 
Altitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshopAltitude NY 2018: Programming the edge workshop
Altitude NY 2018: Programming the edge workshop
 
Functional tests for dummies
Functional tests for dummiesFunctional tests for dummies
Functional tests for dummies
 
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, EverAltitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
Altitude NY 2018: Leveraging Log Streaming to Build the Best Dashboards, Ever
 
Webscraping with asyncio
Webscraping with asyncioWebscraping with asyncio
Webscraping with asyncio
 
My way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionMy way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca edition
 
Clojure: Simple By Design
Clojure: Simple By DesignClojure: Simple By Design
Clojure: Simple By Design
 

Similar a Hypermedia-driven Web Services with Spring Data REST

JLeRN Paradata Challenge at Dev8D 2012
JLeRN Paradata Challenge at Dev8D 2012JLeRN Paradata Challenge at Dev8D 2012
JLeRN Paradata Challenge at Dev8D 2012
Bharti Gupta
 
將 Open Data 放上 Open Source Platforms: 開源資料入口平台 CKAN 開發經驗分享
將 Open Data 放上 Open Source Platforms: 開源資料入口平台 CKAN 開發經驗分享將 Open Data 放上 Open Source Platforms: 開源資料入口平台 CKAN 開發經驗分享
將 Open Data 放上 Open Source Platforms: 開源資料入口平台 CKAN 開發經驗分享
Chengjen Lee
 

Similar a Hypermedia-driven Web Services with Spring Data REST (20)

Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguajeKotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
 
JLeRN Paradata Challenge at Dev8D 2012
JLeRN Paradata Challenge at Dev8D 2012JLeRN Paradata Challenge at Dev8D 2012
JLeRN Paradata Challenge at Dev8D 2012
 
VMUG - Mastering PowerShell to Call RESTful API Endpoints
VMUG - Mastering PowerShell to Call RESTful API EndpointsVMUG - Mastering PowerShell to Call RESTful API Endpoints
VMUG - Mastering PowerShell to Call RESTful API Endpoints
 
Neo4j Introduction (for Techies)
Neo4j Introduction (for Techies)Neo4j Introduction (for Techies)
Neo4j Introduction (for Techies)
 
A miało być tak... bez wycieków
A miało być tak... bez wyciekówA miało być tak... bez wycieków
A miało być tak... bez wycieków
 
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem novaKotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
 
The Devil and HTML5
The Devil and HTML5The Devil and HTML5
The Devil and HTML5
 
My way to clean android (EN) - Android day salamanca edition
My way to clean android (EN) - Android day salamanca editionMy way to clean android (EN) - Android day salamanca edition
My way to clean android (EN) - Android day salamanca edition
 
REST teori og praksis; REST in theory and practice
REST teori og praksis; REST in theory and practiceREST teori og praksis; REST in theory and practice
REST teori og praksis; REST in theory and practice
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginners
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
A search engine in a world of events and microservices - SF Pot @Meetic
A search engine in a world of events and microservices - SF Pot @MeeticA search engine in a world of events and microservices - SF Pot @Meetic
A search engine in a world of events and microservices - SF Pot @Meetic
 
Oracle Application Express as add-on for Google Apps
Oracle Application Express as add-on for Google AppsOracle Application Express as add-on for Google Apps
Oracle Application Express as add-on for Google Apps
 
Blazing Fast Analytics with MongoDB & Spark
Blazing Fast Analytics with MongoDB & SparkBlazing Fast Analytics with MongoDB & Spark
Blazing Fast Analytics with MongoDB & Spark
 
將 Open Data 放上 Open Source Platforms: 開源資料入口平台 CKAN 開發經驗分享
將 Open Data 放上 Open Source Platforms: 開源資料入口平台 CKAN 開發經驗分享將 Open Data 放上 Open Source Platforms: 開源資料入口平台 CKAN 開發經驗分享
將 Open Data 放上 Open Source Platforms: 開源資料入口平台 CKAN 開發經驗分享
 
Autodiscovery or The long tail of open data
Autodiscovery or The long tail of open dataAutodiscovery or The long tail of open data
Autodiscovery or The long tail of open data
 
Backbonejs for beginners
Backbonejs for beginnersBackbonejs for beginners
Backbonejs for beginners
 
Internet of things
Internet of thingsInternet of things
Internet of things
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
The Quest for an Open Source Data Science Platform
 The Quest for an Open Source Data Science Platform The Quest for an Open Source Data Science Platform
The Quest for an Open Source Data Science Platform
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Hypermedia-driven Web Services with Spring Data REST