REST in โ˜ฎ๏ธ

๐Ÿ‘‘ Long live to the Web ๐Ÿ‘‘

by Adrien Gibrat, Frontend developer @ Oodrive

R&D footer

๐ŸŒ A Network-based architecture

Representational State Transfer (REST)
is the core architecture principle of the Web ๐ŸŽž๏ธ.

Also watch past, present, and future of the Web ๐Ÿฟ by Steve Klabnik ๐Ÿฆ„.

R&D footer

๐Ÿ”— tied to HTTP protocol

Defined by Roy Fielding,
author of the HTTP 1.1 protocol,
also involved in HTML and URI standards.

R&D footer

โ˜‘๏ธ with some rules

REST constraints

  • โ†•๏ธ Clientโ€“server
  • โ†”๏ธ Uniform interface
  • ๐Ÿ”€ Stateless
  • ๐Ÿ”‚ Cacheable
  • โฌ†๏ธ Layered
  • [๐Ÿ”ฃ Code on demand (optional)]
R&D footer

๐Ÿ”€ Stateless + ๐Ÿ”‚ Cache = ๐ŸŒฑ Scalable

  • MVP

    graph LR Client[fa:fa-laptop ] --> Server[fa:fa-server ] Server --> Database(fa:fa-database )
  • Prod

    graph LR Client[fa:fa-laptop ] --> Firewall{fa:fa-fire } Firewall --> LoadBalancer{fa:fa-network-wired } LoadBalancer --> |load| FrontalServer1[fa:fa-server ] LoadBalancer --> |balanced| FrontalServer2[fa:fa-server ] FrontalServer1 --> |cached| Cache{fa:fa-hdd } FrontalServer2 --> |responses| Cache FrontalServer1 --> Database(fa:fa-database ) FrontalServer2 --> Database(fa:fa-database ) Cache --> ExpensiveService(fa:fa-tachometer-alt )
R&D footer

๐Ÿ”‚ Cache + โฌ†๏ธ Layers = ๐Ÿš€ Performance

graph LR Client[fa:fa-laptop ] --> Firewall{fa:fa-fire } Firewall--> Gateway{fa:fa-network-wired } Gateway --> |rate| AnotherCache{fa:fa-hdd } Gateway --> |limited| LoadBalancer{fa:fa-network-wired } AnotherCache --> |debounce| AnotherFrontalServer[fa:fa-server ] AnotherFrontalServer --> AnotherDatabase(fa:fa-database ) Gateway -.-> |monitor| ExpensiveService LoadBalancer --> FrontalServer1[fa:fa-server ] LoadBalancer --> FrontalServer2[fa:fa-server ] FrontalServer1 --> Cache{fa:fa-hdd } FrontalServer2 --> Cache FrontalServer1 --> Database(fa:fa-database ) FrontalServer2 --> Database(fa:fa-database ) Cache --> ExpensiveService(fa:fa-tachometer-alt )
R&D footer

โ†”๏ธ Uniform interface

๐Ÿค˜ SOLID for API

  • Identify resources JSON, CSV, XML or HTML != DB Schema

  • Manipulate representations create, read, update, delete...

  • Self-descriptive messages MIME type, cache, status...

  • Hypermedia links between operations OAI Links, json:api

R&D footer

๐ŸŽ“ Take your time

The effort required to design something is inversely proportional to the simplicity of the result.
[โ€ฆ] REST is very simple.

height:6em Leonard Richardson REST Maturity Model

R&D footer

๐Ÿฑ Takeway

5 simple rules

  1. ๐Ÿ†” URI = resources identifier
  2. ๐Ÿ•น๏ธ HTTP verbs = operation
  3. ๐Ÿงพ Responses = resources representation
  4. ๐Ÿ”— Links = relation between resources / operations
  5. ๐Ÿ”‘ Authentication tokens = parameter
R&D footer

๐Ÿ™‹ but you already know it!

R&D footer

๐Ÿ†” URI

  • ๐Ÿ…ฐ๏ธ /books/filter/polar/sort/asc
  • ๐Ÿ…ฑ๏ธ /books?filter=polar&sort=asc
R&D footer

๐Ÿ•น๏ธ Verbs

  • ๐Ÿ…ฐ๏ธ PATCH /books/42
  • ๐Ÿ…ฑ๏ธ POST /books/edit/42
R&D footer

๐Ÿงพ Representations

GET /books
*request header*โ“: application/json
  • ๐Ÿ…ฐ๏ธ Content-Type
  • ๐Ÿ…ฑ๏ธ Accept
R&D footer

๐Ÿ”— Links

  • ๐Ÿ…ฐ๏ธ Link: </books?offset=2>; page="2"
  • ๐Ÿ…ฑ๏ธ Link: </books?offset=2>; rel="next"
R&D footer

๐Ÿ”‘ Tokens

  • ๐Ÿ…ฐ๏ธ Authorization: Bearer YWxhโ€ฆ
  • ๐Ÿ…ฑ๏ธ ?token=zmlPโ€ฆ
  • ๐Ÿ†Ž secure in URL, if short lived/single usage token
R&D footer

๐Ÿ™‚ Thank you

R&D footer

Hello Dhaya, this talk use the Presentation API ;)

First video is 10`, second is 50`

HTTP 2 & HTTP 3 are low layers optimizations for huge performance boost, without large impact or breaking changes to application layers.

We'll see why those simple constraints matters. I Won't talk about "Clientโ€“server", it's pretty obvious, nor about "Code on demand". Let's keep "Uniform interface" for later.

Enables intermediate processing by constraining messages to be self-descriptive: interaction is stateless between requests, standard methods and media types are used to indicate semantics and exchange information, and responses explicitly indicate cacheability.

Allow intermediariesโ€”proxies, gateways, and firewallsโ€”to be introduced at various points in the communication without changing the interfaces between components, thus allowing them to assist in communication translation or improve performance via large-scale, shared caching.

- modifiability of components to meet changing needs (even while the application is running) - visibility of communication between components by service agents - portability of components by moving program code with the data - reliability in the resistance to failure at the system level in the presence of failures within components, connectors, or data

A model, developed by Leonard Richardson, that breaks down the principal elements of a REST approach into three steps. These introduce resources, http verbs, and hypermedia controls.

Take a mental (or actual) picture

๐Ÿ…ฑ๏ธ

๐Ÿ…ฐ๏ธ

๐Ÿ…ฑ๏ธ

๐Ÿ…ฑ๏ธ

๐Ÿ†Ž

It's my last R&Day talk :/ See you @ Open R&Day