SlideShare a Scribd company logo
Tel Aviv, 2017Volodymyr Tsukur @ Engineering Meetup
Hypermedia APIs
and <HATEOAS>
REST
Volodymyr Tsukur
partner @
software
engineer @
flushdia vtsukur
program
committee @
Web / HTTP API
Richardson Maturity Model
Hypermedia APIs and HATEOAS / Wix Engineering
6
{
"user": "Noah",
"title": "Meets expectations",
"comment": "hey dude,
you make America Great Again!",
"rank": 10
}
Trump Feedback API
7
{
"user": "Shai",
"title": "!",
"comment": "oh you s** ** a bi***,
how could people elect someone like
you, ******* ******* ???",
"rank": 1
}
Trump Feedback API
DEMO TIME !
9
Method URL Task
POST /reviews Create
GET /reviews View all
GET /reviews/{id} Get
PATCH / PUT /reviews/{id} Update
DELETE /reviews/{id} Delete
CRUD Style API
Hypermedia APIs and HATEOAS / Wix Engineering
if (status == Status.NEW) {
submittedAt = LocalDateTime.now()
status = Status.SUBMITTED
} …
CRUD is NOT enough
create submit accept
update
delete
NEW
DELETED
SUBMITTED ACCEPTED
12
Method URL Task
PUT /reviews/{id}/submission Submit
PUT /reviews/{id}/acceptance Accept
GET /reviews/search/accepted
Get accepted
reviews
API Changes
DEMO TIME !
/uri Style Adoption?
43%
Richardson Maturity Model
Hypermedia APIs and HATEOAS / Wix Engineering
17
Task Method URL
Update PATCH /reviews/{id}
Delete DELETE /reviews/{id}
Submit PUT /reviews/{id}/submission
Accept PUT /reviews/{id}/acceptance
URL Binding & Construction
URL Change Drivers
URL Change Drivers
• monolith → micro-services
• deployment requirements / proxies
• resource renaming
• optimization by client proximity
• caching
• …
20
Task Method URL
Update
(only if NEW) PATCH /reviews/{id}
Delete
(only if NEW) DELETE /reviews/{id}
Submit
(only if NEW) PUT /reviews/{id}/submission
Accept
(only if
SUBMITTED)
PUT /reviews/{id}/acceptance
"Figuring" Out the Flow
Security!
22
Task Method URL
Update
(only if NEW and user
has permissions)
PATCH /reviews/{id}
Delete
(only if NEW and user
has permissions)
DELETE /reviews/{id}
Submit
(only if NEW and user
has permissions)
PUT /reviews/{id}/submission
Accept
(only if SUBMITTED and
user has permissions)
PUT /reviews/{id}/acceptance
Security!
Hypermedia APIs and HATEOAS / Wix Engineering
Hypermedia APIs and HATEOAS / Wix Engineering
"Hypermedia" =
{
"user": "Aviran",
"title": "...",
…
}
data
{
…
"_links": {
"submission": {
"href": "/reviews/7/submission"
},
"update": {
"href": "/reviews/7"
},
"deletion": {
"href": "/reviews/7"
}
}
}
link
+
26
Link Relation Task Method
update Update PATCH
deletion Delete DELETE
submission Submit PUT
acceptance Accept PUT
Hypermedia API
DEMO TIME !
Hypermedia Client
if (review._links.has("submission")) {
// draw submit button / UI
}
Non-Hypermedia Client
Hypermedia Client
"Simple" Hypermedia
✓where to go?
✓when?
- how?
"I want hypermedia!" (2014)
0 %
7 %
14 %
21 %
28 %
Hypermedia SOAP CRUD
40%
"I want hypermedia!" (2015)
Hypermedia APIs and HATEOAS / Wix Engineering
Hypermedia APIs and HATEOAS / Wix Engineering
«A REST API should spend almost all of its
descriptive effort in defining the media type(s)
used for representing resources and driving
application state, or in defining extended relation
names and/or hypertext-enabled mark-up for
existing standard media types.»
Roy T. Fielding, 2008
Hypertext Application Language
Mason{
"name": "Aviran",
"title": "…",
…
"@controls": {
"user": {
"href": "/users/3"
},
"review-submission": {
"href": "/reviews/7/submission",
"method": "PUT"
}
}
}
Hypermedia Factors
level of hypermedia support
CL = Link Semantics
"_links": {
"review": {
"href": "/reviews/7"
}
}
IANA Link Relations
Name Description RFC
self Conveys an identifier for the link's context. RFC4287
first An IRI that refers to the furthest preceding resource in a series of resources. RFC5988
last An IRI that refers to the furthest following resource in a series of resources. RFC5988
up Refers to a parent document in a hierarchy of documents. RFC5988
item
The target IRI points to a resource that is a member of the collection
represented by the context IRI. RFC6573
collection
The target IRI points to a resource which represents the collection resource for
the context IRI. RFC6573
edit Refers to a resource that can be used to edit the link's context. RFC5023
prev/previous
Indicates that the link's context is a part of a series, and that the previous in the
series is the link target. HTML5
next
Indicates that the link's context is a part of a series, and that the next in the
series is the link target. HTML5
IANA Link Relations
Name Description RFC
create-form
The target IRI points to a resource where a submission form can be
obtained. RFC6861
edit-form
The target IRI points to a resource where a submission form for editing
associated resource can be obtained. RFC6861
payment Indicates a resource where payment is accepted RFC5988
latest-version
Points to a resource containing the latest (e.g., current) version of the
context. RFC5829
profile
Identifying that a resource representation conforms to a certain profile,
without affecting the non-profile semantics of the resource representation. RFC6906
search
Refers to a resource that can be used to search through the link's context
and related resources. OpenSearch
index Refers to an index. HTML4
about Refers to a resource that is the subject of the link's context. RFC6903
help Refers to context-sensitive help. HTML5
CL = Link Semantics
<link rel="stylesheet" src="styles.css" />
LE = Link Outbound
"_links": {
"user": {
"href": "/users/7"
}
}
LE = Link Outbound
<a href="/review/1536c64.html">
Shai says "!", rating: 1
</a>
LE = Link Embedded
"_embedded": {
"ratings": [
{ "id": "7", … },
{ "id": "8", … },
]
}
LE = Link Embedded
<img src="/images/cities/tel-aviv.jpg">
LT = Templated Queries
"_links": {
"review-by-id": {
"href": "/reviews{/id}",
"templated": true
}
}
LT = Templated Queries
"_links": {
"reviews": {
"href": "/reviews{?page,size,sort}",
"templated": true
}
}
RFC 6570
LT = Templated Queries
<form method="get" action="/hotels/search">
<input name="query" type="text">
<input type="submit">
</form>
LN = Non-Idemp. Updates
"actions": [
{
"name": "create-review",
"method": "POST",
"href": "/reviews",
"type": "application/json",
"fields": [
{ "name": "user", "type": "text" },
{ "name": "title", "type": "text" },
{ "name": "comment", "type": "text" },
{ "name": "rank", "type": "number" }, …
]
}
]
<form method="post" action="/reviews">
<input name="user" type="text">
<input name="title" type="text">
<input name="comment" type="text">
…
<input type="submit">
</form>
LN = Non-Idemp. Updates
LN = Idempotent Updates
"actions": [
{
"name": "delete-review",
"method": "DELETE",
"href": "/reviews/7"
}
]
CM = Method Modification
"actions": [
{
"name": "delete-rating",
"method": "DELETE",
"href": "/ratings/1"
}
]
CR = Read Modification
"_links": {
"ballot": [
{
"name": "ballot-json",
"href": "/reviews/7",
"type": "application/json"
}
{
"name": "ballot-xml",
"href": "/reviews/7",
"type": "application/xml"
}
]
}
Hypermedia Factors
?What about and
Hypermedia Factors
HTML XML JSON
LE ⩗ ⊗ ⊗
LO ⩗ ⊗ ⊗
LT ⩗ ⊗ ⊗
LN ⩗ ⊗ ⊗
LI ⊗ ⊗ ⊗
CR ⊗ ⊗ ⊗
CU ⩗ ⊗ ⊗
CM ⩗ ⊗ ⊗
CL ⩗ ⊗ ⊗
JSON-based Media Types
JSON-LD JSON API HAL Cj Siren Mason Uber
LE ⩗ ⩗ ⩗ ⩗ ⩗ ⩗ ⩗
LO ⩗ ⩗ ⩗ ⩗ ⩗ ⩗ ⩗
LT ⊗ ⩗ ⩗ ⩗ ⊗ ⩗ ⩗
LN ⊗ ⊗ ⊗ ⩗ ⩗ ⩗ ⩗
LI ⊗ ⊗ ⊗ ⩗ ⩗ ⩗ ⩗
CR ⊗ ⊗ ⩗ ⊗ ⩗ ⩗ ⩗
CU ⊗ ⊗ ⊗ ⊗ ⩗ ⩗ ⩗
CM ⊗ ⊗ ⊗ ⊗ ⩗ ⩗ ⩗
CL ⩗ ⩗ ⩗ ⩗ ⩗ ⩗ ⩗
Before Choosing Media Type
• list information client would want
from the API
• draw state diagram
-think "tasks"
-"(non-)idempotent", "(un-)safe"
{
"@id": "http://trump.feedback/reviews/7",
"@context": "http://trump.feedback/schema/review.jsonld",
"user": "Shai",
"title": "!",
"comment": "oh you s** ** a bi*** ...",
"rank": 1,
…
}
JSON-LD
{
"@context": {
"user": "http://schema.org/name",
"title": "https://schema.org/title",
"comment": "https://schema.org/comment",
"rank": "https://schema.org/ratingValue"
…
}
}
http://trump-feedback/schema/rating.jsonld
{
"@id": "http://trump-feedback/reviews/7",
…
"supportedOperations": [
{
"@type": "ReviewSubmission",
"method": "PUT",
"expects": "#Review"
}
]
}
JSON-LD + Hydra
{
"class": [ "review" ],
"properties": {
"user": "Aviran",
"title": "...",
…
},
"links": …,
"actions": [
{
"name": "review-submission",
"href": "/reviews/7",
"method": "PUT",
…
}
]
}
SIREN
CL = Link Semantics
"_links": {
"review": {
"href": "/reviews/7"
}
}
CL = Link Semantics
"_links": {
"http://trump-feedback/rels/review": {
"href": "/reviews/7"
}
}
CL = Link Semantics
"_links": {
"urn:trump-feedback/rels/review": {
"href": "/reviews/1"
}
}
CL = Link Semantics
"_links": {
"trump-feedback:review": {
"href": "/reviews/1"
}
}
CompactURIE
trump-feedback=
http://trump-feedback/rels/{rel}
trump-feedback:review
http://trump-feedback.com/rels/review
DEMO TIME !
Documentation
• no URLs except of the entry point
• resources
• links (namespaces)
• HTTP status codes, verbs
• authentication, rate limiting
• errors
Mason{
"name": "Aviran",
"title": "...",
…
"@namespaces": {
"trump-feedback": { "name": "http://trump-feedback/rels/" }
},
"@controls": {
"trump-feedback:user": { "href": "/users/3" },
"trump-feedback:review-submission": {
"href": "/reviews/7/submission",
"method": "PUT"
}
}
}
Profiles
✓where to go?
✓when?
✓how?
DEMO TIME !
Richardson Maturity Model
Hypermedia APIs and HATEOAS / Wix Engineering
References
1. http://www.google.com.ua/trends/explore#q=web%20api%2C%20rest%20api&cmpt=q&tz=
2. http://finance.i.ua/market/
3. http://projects.spring.io/spring-boot/
4. http://projects.spring.io/spring-data/
5. http://docs.spring.io/spring-data/jpa/docs/1.7.2.RELEASE/reference/html/
6. http://projects.spring.io/spring-data-rest/
7. http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/
8. https://spring.io/blog/2014/07/14/spring-data-rest-now-comes-with-alps-metadata
9. http://projects.spring.io/spring-hateoas/
10. http://docs.spring.io/spring-hateoas/docs/0.17.0.RELEASE/reference/html/
11. https://github.com/spring-projects/spring-restdocs
12. https://blog.akana.com/hypermedia-apis
13. http://www.apiacademy.co/lessons/api-design/web-api-architectural-styles
14. http://www.programmableweb.com/news/modern-api-architectural-styles-offer-developers-choices/2014/06/13
15. https://en.wikipedia.org/wiki/Hypermedia
16. http://stateless.co/hal_specification.html
17. https://github.com/kevinswiber/siren
18. https://www.mnot.net/blog/2013/06/23/linking_apis
19. http://oredev.org/2010/sessions/hypermedia-apis
20. http://vimeo.com/75106815
21. https://www.innoq.com/blog/st/2012/06/hypermedia-benefits-for-m2m-communication/
22. http://ws-rest.org/2014/sites/default/files/wsrest2014_submission_12.pdf
23. http://www.infoq.com/news/2014/03/ca-api-survey
24. https://twitter.com/hypermediaapis
25. https://www.youtube.com/watch?v=hdSrT4yjS1g
26. https://www.youtube.com/watch?v=mZ8_QgJ5mbs
27. http://nordsc.com/ext/classification_of_http_based_apis.html
28. http://soabits.blogspot.no/2013/12/selling-benefits-of-hypermedia.html
29. https://github.com/mamund/Building-Hypermedia-APIs
30. http://tech.blog.box.com/2013/04/get-developer-hugs-with-rich-error-handling-in-your-api/
Ad

Recommended

Hypermedia APIs and HATEOAS
Hypermedia APIs and HATEOAS
Vladimir Tsukur
 
From CRUD to Hypermedia APIs with Spring
From CRUD to Hypermedia APIs with Spring
Vladimir Tsukur
 
Building Awesome API with Spring
Building Awesome API with Spring
Vladimir Tsukur
 
Together Cheerfully to Walk with Hypermedia
Together Cheerfully to Walk with Hypermedia
Vladimir Tsukur
 
Representational State Transfer (REST) and HATEOAS
Representational State Transfer (REST) and HATEOAS
Guy K. Kloss
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
David Gómez G. - Hypermedia APIs for headless platforms and Data Integration ...
Codemotion
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
[DevCrowd] GraphQL - gdy API RESTowe to za mało
[DevCrowd] GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
MarcinStachniuk
 
GraphQL - gdy API RESTowe to za mało
GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
The REST And Then Some
The REST And Then Some
Nordic APIs
 
Training and Face Recognition in 5 Easy Steps with VisageCloud
Training and Face Recognition in 5 Easy Steps with VisageCloud
Bogdan Bocse
 
AMS, API, RAILS and a developer, a Love Story
AMS, API, RAILS and a developer, a Love Story
João Moura
 
How to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet api
E Boisgontier
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Shreeraj Shah
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Example-driven Web API Specification Discovery
Example-driven Web API Specification Discovery
Javier Canovas
 
JSON Injection
JSON Injection
n|u - The Open Security Community
 
RESTful Services
RESTful Services
Jason Gerard
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
ruyalarcon
 
იოსებ ძმანაშვილი - The Web APIs
იოსებ ძმანაშვილი - The Web APIs
unihack
 
Restful风格ž„web服务架构
Restful风格ž„web服务架构
Benjamin Tan
 
REST Methodologies
REST Methodologies
jrodbx
 
Hypermedia
Hypermedia
Adam Culp
 
Thinking restfully
Thinking restfully
Stelios Gorilas
 
Introduction to the Web API
Introduction to the Web API
Brad Genereaux
 
RESTful APIs
RESTful APIs
Adi Challa
 
Netflix OSS and HATEOAS deployed on production - JavaLand
Netflix OSS and HATEOAS deployed on production - JavaLand
JWORKS powered by Ordina
 

More Related Content

What's hot (12)

[DevCrowd] GraphQL - gdy API RESTowe to za mało
[DevCrowd] GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
MarcinStachniuk
 
GraphQL - gdy API RESTowe to za mało
GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
The REST And Then Some
The REST And Then Some
Nordic APIs
 
Training and Face Recognition in 5 Easy Steps with VisageCloud
Training and Face Recognition in 5 Easy Steps with VisageCloud
Bogdan Bocse
 
AMS, API, RAILS and a developer, a Love Story
AMS, API, RAILS and a developer, a Love Story
João Moura
 
How to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet api
E Boisgontier
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Shreeraj Shah
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Example-driven Web API Specification Discovery
Example-driven Web API Specification Discovery
Javier Canovas
 
JSON Injection
JSON Injection
n|u - The Open Security Community
 
[DevCrowd] GraphQL - gdy API RESTowe to za mało
[DevCrowd] GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
MarcinStachniuk
 
GraphQL - gdy API RESTowe to za mało
GraphQL - gdy API RESTowe to za mało
MarcinStachniuk
 
The REST And Then Some
The REST And Then Some
Nordic APIs
 
Training and Face Recognition in 5 Easy Steps with VisageCloud
Training and Face Recognition in 5 Easy Steps with VisageCloud
Bogdan Bocse
 
AMS, API, RAILS and a developer, a Love Story
AMS, API, RAILS and a developer, a Love Story
João Moura
 
How to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet api
E Boisgontier
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Shreeraj Shah
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Example-driven Web API Specification Discovery
Example-driven Web API Specification Discovery
Javier Canovas
 

Similar to Hypermedia APIs and HATEOAS / Wix Engineering (20)

RESTful Services
RESTful Services
Jason Gerard
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
ruyalarcon
 
იოსებ ძმანაშვილი - The Web APIs
იოსებ ძმანაშვილი - The Web APIs
unihack
 
Restful风格ž„web服务架构
Restful风格ž„web服务架构
Benjamin Tan
 
REST Methodologies
REST Methodologies
jrodbx
 
Hypermedia
Hypermedia
Adam Culp
 
Thinking restfully
Thinking restfully
Stelios Gorilas
 
Introduction to the Web API
Introduction to the Web API
Brad Genereaux
 
RESTful APIs
RESTful APIs
Adi Challa
 
Netflix OSS and HATEOAS deployed on production - JavaLand
Netflix OSS and HATEOAS deployed on production - JavaLand
JWORKS powered by Ordina
 
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
Inviqa
 
Making Sense of Hypermedia APIs – Hype or Reality?
Making Sense of Hypermedia APIs – Hype or Reality?
Akana
 
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
JWORKS powered by Ordina
 
Representational State Transfer
Representational State Transfer
Alexei Skachykhin
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan Ullah
Cefalo
 
Hypermedia APIs - GeekOut
Hypermedia APIs - GeekOut
Jan Kronquist
 
A Deep Dive into RESTful API Design Part 1
A Deep Dive into RESTful API Design Part 1
VivekKrishna34
 
Five API Styles
Five API Styles
ronniemitra
 
Approaches to machine actionable links
Approaches to machine actionable links
Stephen Richard
 
REST & RESTful APIs: The State of Confusion
REST & RESTful APIs: The State of Confusion
Glenn Antoine
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
ruyalarcon
 
იოსებ ძმანაშვილი - The Web APIs
იოსებ ძმანაშვილი - The Web APIs
unihack
 
Restful风格ž„web服务架构
Restful风格ž„web服务架构
Benjamin Tan
 
REST Methodologies
REST Methodologies
jrodbx
 
Introduction to the Web API
Introduction to the Web API
Brad Genereaux
 
Netflix OSS and HATEOAS deployed on production - JavaLand
Netflix OSS and HATEOAS deployed on production - JavaLand
JWORKS powered by Ordina
 
REST and the Hypermedia Constraint
REST and the Hypermedia Constraint
Inviqa
 
Making Sense of Hypermedia APIs – Hype or Reality?
Making Sense of Hypermedia APIs – Hype or Reality?
Akana
 
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
JWORKS powered by Ordina
 
Representational State Transfer
Representational State Transfer
Alexei Skachykhin
 
Overview of REST - Raihan Ullah
Overview of REST - Raihan Ullah
Cefalo
 
Hypermedia APIs - GeekOut
Hypermedia APIs - GeekOut
Jan Kronquist
 
A Deep Dive into RESTful API Design Part 1
A Deep Dive into RESTful API Design Part 1
VivekKrishna34
 
Approaches to machine actionable links
Approaches to machine actionable links
Stephen Richard
 
REST & RESTful APIs: The State of Confusion
REST & RESTful APIs: The State of Confusion
Glenn Antoine
 
Ad

More from Vladimir Tsukur (8)

GraphQL APIs in Scala with Sangria
GraphQL APIs in Scala with Sangria
Vladimir Tsukur
 
GraphQL - APIs The New Way
GraphQL - APIs The New Way
Vladimir Tsukur
 
Hot and spicy Java with Lombok. Live!
Hot and spicy Java with Lombok. Live!
Vladimir Tsukur
 
Take a REST!
Take a REST!
Vladimir Tsukur
 
Law of Demeter & Objective Sense of Style
Law of Demeter & Objective Sense of Style
Vladimir Tsukur
 
Abstraction Classes in Software Design
Abstraction Classes in Software Design
Vladimir Tsukur
 
Acceptance Testing of Web UI
Acceptance Testing of Web UI
Vladimir Tsukur
 
REpresentational State Transfer
REpresentational State Transfer
Vladimir Tsukur
 
GraphQL APIs in Scala with Sangria
GraphQL APIs in Scala with Sangria
Vladimir Tsukur
 
GraphQL - APIs The New Way
GraphQL - APIs The New Way
Vladimir Tsukur
 
Hot and spicy Java with Lombok. Live!
Hot and spicy Java with Lombok. Live!
Vladimir Tsukur
 
Law of Demeter & Objective Sense of Style
Law of Demeter & Objective Sense of Style
Vladimir Tsukur
 
Abstraction Classes in Software Design
Abstraction Classes in Software Design
Vladimir Tsukur
 
Acceptance Testing of Web UI
Acceptance Testing of Web UI
Vladimir Tsukur
 
REpresentational State Transfer
REpresentational State Transfer
Vladimir Tsukur
 
Ad

Recently uploaded (20)

PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 

Hypermedia APIs and HATEOAS / Wix Engineering

  • 1. Tel Aviv, 2017Volodymyr Tsukur @ Engineering Meetup Hypermedia APIs and <HATEOAS>
  • 2. REST Volodymyr Tsukur partner @ software engineer @ flushdia vtsukur program committee @
  • 6. 6 { "user": "Noah", "title": "Meets expectations", "comment": "hey dude, you make America Great Again!", "rank": 10 } Trump Feedback API
  • 7. 7 { "user": "Shai", "title": "!", "comment": "oh you s** ** a bi***, how could people elect someone like you, ******* ******* ???", "rank": 1 } Trump Feedback API
  • 9. 9 Method URL Task POST /reviews Create GET /reviews View all GET /reviews/{id} Get PATCH / PUT /reviews/{id} Update DELETE /reviews/{id} Delete CRUD Style API
  • 11. if (status == Status.NEW) { submittedAt = LocalDateTime.now() status = Status.SUBMITTED } … CRUD is NOT enough create submit accept update delete NEW DELETED SUBMITTED ACCEPTED
  • 12. 12 Method URL Task PUT /reviews/{id}/submission Submit PUT /reviews/{id}/acceptance Accept GET /reviews/search/accepted Get accepted reviews API Changes
  • 17. 17 Task Method URL Update PATCH /reviews/{id} Delete DELETE /reviews/{id} Submit PUT /reviews/{id}/submission Accept PUT /reviews/{id}/acceptance URL Binding & Construction
  • 19. URL Change Drivers • monolith → micro-services • deployment requirements / proxies • resource renaming • optimization by client proximity • caching • …
  • 20. 20 Task Method URL Update (only if NEW) PATCH /reviews/{id} Delete (only if NEW) DELETE /reviews/{id} Submit (only if NEW) PUT /reviews/{id}/submission Accept (only if SUBMITTED) PUT /reviews/{id}/acceptance "Figuring" Out the Flow
  • 22. 22 Task Method URL Update (only if NEW and user has permissions) PATCH /reviews/{id} Delete (only if NEW and user has permissions) DELETE /reviews/{id} Submit (only if NEW and user has permissions) PUT /reviews/{id}/submission Accept (only if SUBMITTED and user has permissions) PUT /reviews/{id}/acceptance Security!
  • 25. "Hypermedia" = { "user": "Aviran", "title": "...", … } data { … "_links": { "submission": { "href": "/reviews/7/submission" }, "update": { "href": "/reviews/7" }, "deletion": { "href": "/reviews/7" } } } link +
  • 26. 26 Link Relation Task Method update Update PATCH deletion Delete DELETE submission Submit PUT acceptance Accept PUT Hypermedia API
  • 31. "Simple" Hypermedia ✓where to go? ✓when? - how?
  • 32. "I want hypermedia!" (2014) 0 % 7 % 14 % 21 % 28 % Hypermedia SOAP CRUD
  • 36. «A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state, or in defining extended relation names and/or hypertext-enabled mark-up for existing standard media types.» Roy T. Fielding, 2008
  • 38. Mason{ "name": "Aviran", "title": "…", … "@controls": { "user": { "href": "/users/3" }, "review-submission": { "href": "/reviews/7/submission", "method": "PUT" } } }
  • 39. Hypermedia Factors level of hypermedia support
  • 40. CL = Link Semantics "_links": { "review": { "href": "/reviews/7" } }
  • 41. IANA Link Relations Name Description RFC self Conveys an identifier for the link's context. RFC4287 first An IRI that refers to the furthest preceding resource in a series of resources. RFC5988 last An IRI that refers to the furthest following resource in a series of resources. RFC5988 up Refers to a parent document in a hierarchy of documents. RFC5988 item The target IRI points to a resource that is a member of the collection represented by the context IRI. RFC6573 collection The target IRI points to a resource which represents the collection resource for the context IRI. RFC6573 edit Refers to a resource that can be used to edit the link's context. RFC5023 prev/previous Indicates that the link's context is a part of a series, and that the previous in the series is the link target. HTML5 next Indicates that the link's context is a part of a series, and that the next in the series is the link target. HTML5
  • 42. IANA Link Relations Name Description RFC create-form The target IRI points to a resource where a submission form can be obtained. RFC6861 edit-form The target IRI points to a resource where a submission form for editing associated resource can be obtained. RFC6861 payment Indicates a resource where payment is accepted RFC5988 latest-version Points to a resource containing the latest (e.g., current) version of the context. RFC5829 profile Identifying that a resource representation conforms to a certain profile, without affecting the non-profile semantics of the resource representation. RFC6906 search Refers to a resource that can be used to search through the link's context and related resources. OpenSearch index Refers to an index. HTML4 about Refers to a resource that is the subject of the link's context. RFC6903 help Refers to context-sensitive help. HTML5
  • 43. CL = Link Semantics <link rel="stylesheet" src="styles.css" />
  • 44. LE = Link Outbound "_links": { "user": { "href": "/users/7" } }
  • 45. LE = Link Outbound <a href="/review/1536c64.html"> Shai says "!", rating: 1 </a>
  • 46. LE = Link Embedded "_embedded": { "ratings": [ { "id": "7", … }, { "id": "8", … }, ] }
  • 47. LE = Link Embedded <img src="/images/cities/tel-aviv.jpg">
  • 48. LT = Templated Queries "_links": { "review-by-id": { "href": "/reviews{/id}", "templated": true } }
  • 49. LT = Templated Queries "_links": { "reviews": { "href": "/reviews{?page,size,sort}", "templated": true } }
  • 51. LT = Templated Queries <form method="get" action="/hotels/search"> <input name="query" type="text"> <input type="submit"> </form>
  • 52. LN = Non-Idemp. Updates "actions": [ { "name": "create-review", "method": "POST", "href": "/reviews", "type": "application/json", "fields": [ { "name": "user", "type": "text" }, { "name": "title", "type": "text" }, { "name": "comment", "type": "text" }, { "name": "rank", "type": "number" }, … ] } ]
  • 53. <form method="post" action="/reviews"> <input name="user" type="text"> <input name="title" type="text"> <input name="comment" type="text"> … <input type="submit"> </form> LN = Non-Idemp. Updates
  • 54. LN = Idempotent Updates "actions": [ { "name": "delete-review", "method": "DELETE", "href": "/reviews/7" } ]
  • 55. CM = Method Modification "actions": [ { "name": "delete-rating", "method": "DELETE", "href": "/ratings/1" } ]
  • 56. CR = Read Modification "_links": { "ballot": [ { "name": "ballot-json", "href": "/reviews/7", "type": "application/json" } { "name": "ballot-xml", "href": "/reviews/7", "type": "application/xml" } ] }
  • 58. Hypermedia Factors HTML XML JSON LE ⩗ ⊗ ⊗ LO ⩗ ⊗ ⊗ LT ⩗ ⊗ ⊗ LN ⩗ ⊗ ⊗ LI ⊗ ⊗ ⊗ CR ⊗ ⊗ ⊗ CU ⩗ ⊗ ⊗ CM ⩗ ⊗ ⊗ CL ⩗ ⊗ ⊗
  • 59. JSON-based Media Types JSON-LD JSON API HAL Cj Siren Mason Uber LE ⩗ ⩗ ⩗ ⩗ ⩗ ⩗ ⩗ LO ⩗ ⩗ ⩗ ⩗ ⩗ ⩗ ⩗ LT ⊗ ⩗ ⩗ ⩗ ⊗ ⩗ ⩗ LN ⊗ ⊗ ⊗ ⩗ ⩗ ⩗ ⩗ LI ⊗ ⊗ ⊗ ⩗ ⩗ ⩗ ⩗ CR ⊗ ⊗ ⩗ ⊗ ⩗ ⩗ ⩗ CU ⊗ ⊗ ⊗ ⊗ ⩗ ⩗ ⩗ CM ⊗ ⊗ ⊗ ⊗ ⩗ ⩗ ⩗ CL ⩗ ⩗ ⩗ ⩗ ⩗ ⩗ ⩗
  • 60. Before Choosing Media Type • list information client would want from the API • draw state diagram -think "tasks" -"(non-)idempotent", "(un-)safe"
  • 62. { "@context": { "user": "http://schema.org/name", "title": "https://schema.org/title", "comment": "https://schema.org/comment", "rank": "https://schema.org/ratingValue" … } } http://trump-feedback/schema/rating.jsonld
  • 63. { "@id": "http://trump-feedback/reviews/7", … "supportedOperations": [ { "@type": "ReviewSubmission", "method": "PUT", "expects": "#Review" } ] } JSON-LD + Hydra
  • 64. { "class": [ "review" ], "properties": { "user": "Aviran", "title": "...", … }, "links": …, "actions": [ { "name": "review-submission", "href": "/reviews/7", "method": "PUT", … } ] } SIREN
  • 65. CL = Link Semantics "_links": { "review": { "href": "/reviews/7" } }
  • 66. CL = Link Semantics "_links": { "http://trump-feedback/rels/review": { "href": "/reviews/7" } }
  • 67. CL = Link Semantics "_links": { "urn:trump-feedback/rels/review": { "href": "/reviews/1" } }
  • 68. CL = Link Semantics "_links": { "trump-feedback:review": { "href": "/reviews/1" } }
  • 71. Documentation • no URLs except of the entry point • resources • links (namespaces) • HTTP status codes, verbs • authentication, rate limiting • errors
  • 72. Mason{ "name": "Aviran", "title": "...", … "@namespaces": { "trump-feedback": { "name": "http://trump-feedback/rels/" } }, "@controls": { "trump-feedback:user": { "href": "/users/3" }, "trump-feedback:review-submission": { "href": "/reviews/7/submission", "method": "PUT" } } }
  • 77. References 1. http://www.google.com.ua/trends/explore#q=web%20api%2C%20rest%20api&cmpt=q&tz= 2. http://finance.i.ua/market/ 3. http://projects.spring.io/spring-boot/ 4. http://projects.spring.io/spring-data/ 5. http://docs.spring.io/spring-data/jpa/docs/1.7.2.RELEASE/reference/html/ 6. http://projects.spring.io/spring-data-rest/ 7. http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/ 8. https://spring.io/blog/2014/07/14/spring-data-rest-now-comes-with-alps-metadata 9. http://projects.spring.io/spring-hateoas/ 10. http://docs.spring.io/spring-hateoas/docs/0.17.0.RELEASE/reference/html/ 11. https://github.com/spring-projects/spring-restdocs 12. https://blog.akana.com/hypermedia-apis 13. http://www.apiacademy.co/lessons/api-design/web-api-architectural-styles 14. http://www.programmableweb.com/news/modern-api-architectural-styles-offer-developers-choices/2014/06/13 15. https://en.wikipedia.org/wiki/Hypermedia 16. http://stateless.co/hal_specification.html 17. https://github.com/kevinswiber/siren 18. https://www.mnot.net/blog/2013/06/23/linking_apis 19. http://oredev.org/2010/sessions/hypermedia-apis 20. http://vimeo.com/75106815 21. https://www.innoq.com/blog/st/2012/06/hypermedia-benefits-for-m2m-communication/ 22. http://ws-rest.org/2014/sites/default/files/wsrest2014_submission_12.pdf 23. http://www.infoq.com/news/2014/03/ca-api-survey 24. https://twitter.com/hypermediaapis 25. https://www.youtube.com/watch?v=hdSrT4yjS1g 26. https://www.youtube.com/watch?v=mZ8_QgJ5mbs 27. http://nordsc.com/ext/classification_of_http_based_apis.html 28. http://soabits.blogspot.no/2013/12/selling-benefits-of-hypermedia.html 29. https://github.com/mamund/Building-Hypermedia-APIs 30. http://tech.blog.box.com/2013/04/get-developer-hugs-with-rich-error-handling-in-your-api/