Slide 1

Slide 1 text

I Am Hypermedia (And So Can You)

Slide 2

Slide 2 text

JSON API

Slide 3

Slide 3 text

> GET /books < 200 OK [{ id: 42, price: "$10.20", title: "The Hitchhiker's Guide..." }, { id: 43, price: "$11.20", title: "The Restaurant at the End..." }] List Books

Slide 4

Slide 4 text

> GET /books?page=2 < 200 OK [{ id: 44, price: "$11.20", title: "So Long, and Thanks for All..." }] List Books

Slide 5

Slide 5 text

View Book Cover > GET /covers/42 < 200 OK < Content-Type: image/png

Slide 6

Slide 6 text

View Book > GET /books/42 < 200 OK { id: 42, price: "$10.20", title: "The Hitchhiker's Guide...", author: "Douglas Adams", owned: false }

Slide 7

Slide 7 text

Purchase Book > POST /purchases { book_id: 42 } < 201 Created { id: 42, price: "$10.20", title: "The Hitchhiker's Guide...", author: "Douglas Adams", owned: true }

Slide 8

Slide 8 text

Read Book > GET /read/42 < 200 OK > GET /read/43 < 403 Forbidden

Slide 9

Slide 9 text

List Purchases > GET /purchases < 200 OK [{ id: 42, price: "$10.20", title: "The Hitchhiker's Guide...", owned: true }]

Slide 10

Slide 10 text

Ship It!

Slide 11

Slide 11 text

Move Images > GET http://cdn.example.com/42.png < 200 OK < Content-Type: image/png > GET /covers/42 < 302 Found < Location: http://cdn.example.com/42.png

Slide 12

Slide 12 text

Lend Book > POST /lendings { book_id: 42, borrower_id: 13 } < 201 Created { id: 42, title: "The Hitchhiker's Guide...", ... }

Slide 13

Slide 13 text

Lend Book > GET /books/42 < 200 OK { id: 42, title: "The Hitchhiker's Guide...", owned: true, lender_id: 13, ... } > GET /read/42 < 200 OK

Slide 14

Slide 14 text

Lend Book > GET /books/42 < 200 OK { id: 42, title: "The Hitchhiker's Guide...", owned: false, borrower_id: 13, ... } > GET /read/42 < 403 Forbidden

Slide 15

Slide 15 text

RPC

Slide 16

Slide 16 text

Hypermedia

Slide 17

Slide 17 text

Hypermedia (a.k.a. REST)

Slide 18

Slide 18 text

“REST emphasizes scalability of component interactions, generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems.” - Roy T. Fielding

Slide 19

Slide 19 text

Media Types

Slide 20

Slide 20 text

H Factors

Slide 21

Slide 21 text

Embedding Links

Slide 22

Slide 22 text

Outbound Links The Hitchhiker's...

Slide 23

Slide 23 text

Templated Queries

Slide 24

Slide 24 text

Templated Queries GET /search?query=hitchhiker HTTP/1.1 Host: example.org

Slide 25

Slide 25 text

Non-Idempotent Updates

Slide 26

Slide 26 text

Non-Idempotent Updates POST /tags HTTP/1.1 Host: example.org Content-Type: application/x-www-form-urlencoded Content-Length: 29 tag=intergalactic+hitchhiking

Slide 27

Slide 27 text

Idempotent Updates var client = new XMLHttpRequest(); client.open("DELETE", "/tags/" + id); client.send();

Slide 28

Slide 28 text

Read Controls

Slide 29

Slide 29 text

Update Controls

Slide 30

Slide 30 text

Method Controls

Slide 31

Slide 31 text

Link Semantics Next

Slide 32

Slide 32 text

H Factors LE: Embedding links LO: Outbound links LT: Templated queries LN: Non-Idempotent updates LI: Idempotent updates CR: Read control data CU: Update control data CM: Request control data CL: Link control data

Slide 33

Slide 33 text

Hypermedia API

Slide 34

Slide 34 text

> GET / < 200 OK Books Purchases List Books

Slide 35

Slide 35 text

=> books < 200 OK
  1. $10.20 The Hitchhiker's Guide...
  2. ...
Next List Books

Slide 36

Slide 36 text

List Books => next < 200 OK
  1. $11.20 So Long, and Thanks for All...
Prev

Slide 37

Slide 37 text

View Book => self < 200 OK $11.20 The Hitchhiker's... Douglas Adams

Slide 38

Slide 38 text

Purchase Book => submit form < 201 Created $11.20 The Hitchhiker's... Douglas Adams Read => read < 200 OK

Slide 39

Slide 39 text

List Purchases > GET / < 200 OK Books Purchases => purchases < 200 OK
  1. ...

Slide 40

Slide 40 text

Ship It!

Slide 41

Slide 41 text

Move Images => self < 200 OK => self < 200 OK

Slide 42

Slide 42 text

Lend Book => self < 200 OK $11.20 The Hitchhiker's... Douglas Adams Read

Slide 43

Slide 43 text

Lend Book => submit form < 201 Created $11.20 The Hitchhiker's... Douglas Adams

Slide 44

Slide 44 text

Lend Book => self < 200 OK $11.20 The Hitchhiker's... Douglas Adams Read

Slide 45

Slide 45 text

Hypermedia or RPC?

Slide 46

Slide 46 text

I Am Hypermedia (And So Can You) Sources: https://gist.github.com/3962445