True REST design
REST Drivers
REST Drivers
REST Drivers
REST Definition
REST Definition
REST Definition
REST Definition
REST Definition
REST Constraints
REST Constraints
REST Constraints
REST Constraints
REST Constraints
REST Constraints
REST Constraints
Richardson Maturity Model
Richardson Maturity Model. Level 0
Richardson Maturity Model. Level 1
Richardson Maturity Model. Level 2
Richardson Maturity Model. Level 3
Hypermedia Application Language (HAL)
Hypermedia Application Language (HAL)
Hypermedia Application Language (HAL)
Hypermedia Application Language (HAL)
True REST API
References
Questions?
1.14M
Category: internetinternet

True Rest design

1. True REST design

Alexander Vinokurov

2.

ALEXANDER VINOKUROV
S o f t w a re E n g in e e rin g T e a m L e a d e r
• 13+ years in EPAM
• 10+ projects
• Full stack developer

3. REST Drivers

HETEROGENOUS INTEROPERABILITY
3

4. REST Drivers

D E V I C E S VA R I E T Y
4

5. REST Drivers

CLOUD DISTRIBUTION
“It is critical to build a scalable
architecture in order to take
advantage of a scalable
infrastructure”
5

6. REST Definition

REST Definition
UNIVERSITY OF COLIFORNIA, IRVINE
Architectural Styles and the
Design of Network-based
Software Architectures
DISSERTATION
in Information and Computer Science
by
Roy Thomas Fielding
2000
6

7. REST Definition

REST IS NOT:
RPC
REST is not a way to call methods over a network without the overhead of SOAP and WSDL
HTTP
An architecture implemented on top of HTTP is not inherently RESTful
URIs
Having clean URLs does not make the architecture automatically RESTful
Hyper-focus on URIs can actually make designs non-RESTful
7

8. REST Definition

REST IS:
An Architectural Style (set of rules, constrains and recommendations)
We use standards to implement it
Protocol Agnostic
Intended for long-lived network-based applications
8

9. REST Definition

Representational
state transfer состояния
is intended дает
to evoke
an image of о
Передача
репрезентативного
представление
how aкак
well-designed
web application
behaves, a network
of web
том,
ведет себя хорошо
спроектированное
веб-приложение,
pages
where the user
progresses through
an application
byвыбора
selecting
где пользователь
перемещается
по приложению
путем
links,
resulting
in the next
being transferred
the user and
ссылок,
в результате
чегоpage
следующая
страница to
передается
rendered for their
use.
пользователю
и отображается
для дальнейшего использования.
9

10. REST Definition

Client
Request: GET URL: example.org HTTP/1.1
Response: HTTP/1.1 200 OK
Server
Resource
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8"/>
<link type="text/css" rel="stylesheet" href="data:text/css; charset=utf-8"/>
<title>Some Title</title>
<script>
...
</script>
<body>
</body>
</html>
10

11. REST Constraints

Data Storage
Business Logic
Security
1. Client-Server
Processing
Presentation
User Interaction
11

12. REST Constraints

1. Client-Server
State
State
2. Stateless
State
12

13. REST Constraints

1. Client-Server
2. Stateless
Cache
Cache
3. Cache
Cache
13

14. REST Constraints

Client
Caching Proxy
Load Balancer
Servers
1. Client-Server
2. Stateless
3. Cache
4. Uniform Interface
14

15. REST Constraints

1. Client-Server
2. Stateless
3. Cache
4. Uniform Interface
identification of
resources
Manipulation
through
representations
Self-descriptive
messages
Hypermedia as
the engine of
application
state
15

16. REST Constraints

1. Client-Server
2. Stateless
Request
Servers
Response
Load Balancer
5. Layered System
Caching Proxy
4. Uniform Interface
Security Appliance
3. Cache
16

17. REST Constraints

1. Client-Server
Client
Server
Resource
Resource
2. Stateless
3. Cache
4. Uniform Interface
5. Layered System
6. Code-On-Demand
(optional)
17

18. Richardson Maturity Model

API MATURITY
HYPERMEDIA
HTTP
URI
POX Swamp
3
2
1
0
LEVEL 3. Hypertext as the
Engine of Application State
(HATEOAS)
LEVEL 2. Interaction with URI
resources using different HTTP verbs
LEVEL 1. Multiple URI based
resources and single verbs
LEVEL 0. Plain old XML
(POX)
18

19. Richardson Maturity Model. Level 0

HTTP/1.1 200 OK
POST /appointmentService HTTP/1.1
<openSlotRequest date = "2010-01-04" doctor =
"mjones"/>
POST /appointmentService HTTP/1.1
<appointmentRequest>
<slot doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
</appointmentRequest>
<openSlotList>
<slot start = "1400" end = "1450">
<doctor id = "mjones"/>
</slot>
<slot start = "1600" end = "1650">
<doctor id = "mjones"/>
</slot>
</openSlotList>
HTTP/1.1 200 OK
<appointment>
<slot doctor = "mjones" start = "1400" end =
"1450"/>
<patient id = "jsmith"/>
</appointment>
HTTP/1.1 200 OK
<appointmentRequestFailure>
<slot doctor = "mjones" start = "1400" end =
"1450"/>
<patient id = "jsmith"/>
<reason>Slot not available</reason>
</appointmentRequestFailure>
19

20. Richardson Maturity Model. Level 1

RESOURCES
HTTP/1.1 200 OK
POST /doctors/mjones HTTP/1.1
<openSlotRequest date = "2010-01-04"/>
POST /slots/1234 HTTP/1.1
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400" end = "1450"/>
<slot id = "5678" doctor = "mjones" start = "1600" end = "1650"/>
</openSlotList>
HTTP/1.1 200 OK
<appointment>
<slot id = "1234" doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
</appointment>
20

21. Richardson Maturity Model. Level 2

HTTP VERBS
GET /doctors/mjones/slots?date=20100104&status=open
HTTP/1.1
HTTP/1.1 200 OK
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400" end = "1450"/>
<slot id = "5678" doctor = "mjones" start = "1600" end = "1650"/>
</openSlotList>
POST /slots/1234 HTTP/1.1
HTTP/1.1 201 Created
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>
<appointment>
<slot id = "1234" doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
</appointment>
HTTP/1.1 409 Conflict
<openSlotList>
<slot id = "5678" doctor = "mjones" start = "1600" end = "1650"/>
</openSlotList>
21

22. Richardson Maturity Model. Level 3

Hypermedia Controls
HTTP/1.1 200 OK
GET /doctors/mjones/slots?date=20190104&status=open
HTTP/1.1
<openSlotList>
<slot id = "1234" doctor = "mjones" start = "1400" end = "1450">
<link rel = "book" uri = "/slots/1234“ method=“post”/>
</slot>
</openSlotList>
HTTP/1.1 201 Created
POST /slots/1234 HTTP/1.1
<appointmentRequest>
<patient id = "jsmith"/>
</appointmentRequest>
<appointment>
<slot id = "1234" doctor = "mjones" start = "1400" end = "1450"/>
<patient id = "jsmith"/>
<link rel = "self " uri = "/slots/1234/appointment"/>
<link rel = "cancel“ uri = "/slots/1234/appointment/cancel “/>
</appointment>
22

23. Hypermedia Application Language (HAL)

{
"_links": {
"self": { "href": "/orders" },
"curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}",
"templated": true }],
"next": { "href": "/orders?page=2" },
"ea:find": {
"href": "/orders{?id}",
"templated": true
},
"ea:admin": [{
"href": "/admins/5",
"title": "Kate"
}]
},
"currentlyProcessing": 14,
"shippedToday": 20,
"_embedded": {
"ea:order": [{
"_links": {
"self": { "href": "/orders/123" },
"ea:basket": { "href": "/baskets/98712" },
"ea:customer": { "href": "/customers/7809" }
},
"total": 30.00,
"currency": "USD",
"status": "shipped"
}]
}
}
23

24. Hypermedia Application Language (HAL)

{
"_links": {
"self": { "href": "/orders" },
"curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}",
"templated": true }],
"next": { "href": "/orders?page=2" },
"ea:find": {
"href": "/orders{?id}",
"templated": true
},
"ea:admin": [{
"href": "/admins/5",
"title": "Kate"
}]
},
"currentlyProcessing": 14,
"shippedToday": 20,
"_embedded": {
"ea:order": [{
"_links": {
"self": { "href": "/orders/123" },
"ea:basket": { "href": "/baskets/98712" },
"ea:customer": { "href": "/customers/7809" }
},
"total": 30.00,
"currency": "USD",
"status": "shipped"
}]
}
}
24

25. Hypermedia Application Language (HAL)

{
"_links": {
"self": { "href": "/orders" },
"curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}",
"templated": true }],
"next": { "href": "/orders?page=2" },
"ea:find": {
"href": "/orders{?id}",
"templated": true
},
"ea:admin": [{
"href": "/admins/5",
"title": "Kate"
}]
},
"currentlyProcessing": 14,
"shippedToday": 20,
"_embedded": {
"ea:order": [{
"_links": {
"self": { "href": "/orders/123" },
"ea:basket": { "href": "/baskets/98712" },
"ea:customer": { "href": "/customers/7809" }
},
"total": 30.00,
"currency": "USD",
"status": "shipped"
}]
}
}
25

26. Hypermedia Application Language (HAL)

{
"_links": {
"self": { "href": "/orders" },
"curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}",
"templated": true }],
"next": { "href": "/orders?page=2" },
"ea:find": {
"href": "/orders{?id}",
"templated": true
},
"ea:admin": [{
"href": "/admins/5",
"title": "Kate"
}]
},
"currentlyProcessing": 14,
"shippedToday": 20,
"_embedded": {
"ea:order": [{
"_links": {
"self": { "href": "/orders/123" },
"ea:basket": { "href": "/baskets/98712" },
"ea:customer": { "href": "/customers/7809" }
},
"total": 30.00,
"currency": "USD",
"status": "shipped"
}]
}
}
26

27. True REST API

1. Github
2. Facebook for Developers (Graph API)
3. Google Drive REST API
4. API Яндекс Диска
5. Paypal
27

28. References

1. Fielding, Roy Thomas. Architectural Styles and the Design of Networkbased Software Architectures. Doctoral dissertation, University of
California, Irvine, 2000.
https://www.ics.uci.edu/~fielding/pubs/dissertation/fielding_dissertation.pdf
2. REST APIs must be hypertext-driven
https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
3. Richardson Maturity Model
https://martinfowler.com/articles/richardsonMaturityModel.html
4. HAL - Hypertext Application Language
http://stateless.co/hal_specification.html
5. Dylan Beattie — Real World REST and Hands-On Hypermedia
https://youtu.be/kPrTMj-BK14
28

29. Questions?

QUESTIONS?
29
English     Русский Rules