Top Banner
BENEFITS OF HYPERMEDIA APIS Paulo Gandra de Sousa [email protected] om
18

Benefits of Hypermedia API

Apr 12, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Benefits of Hypermedia API

BENEFITS OF HYPERMEDIA

APISPaulo Gandra de [email protected]

Page 2: Benefits of Hypermedia API

3” Hypermedia is defined by the presence of application control information embedded within, or as a layer above, the presentation of information.

Mike Amudsen

Page 3: Benefits of Hypermedia API

THE HYPERMEDIA CONSTRAINT

Hipermedia as the engine of

application state *

* HATEOAS

Page 4: Benefits of Hypermedia API

5

“”

HYPERMEDIA IS THE ENGINE

Hypermedia payloads carry more information than just the data stored on the server. Hypermedia payloads carry two types of vital metadata: metadata about the data itself and metadata about the possible options for modifying the state of the application at that moment.

Mike Amudsen

Page 5: Benefits of Hypermedia API

THE HYPERMEDIA CONSTRAINT

The application is therefore an engine that moves from one state to the next by examining and choosing from among the alternative state transitions in the current set of representations.

Roy Fielding

6

“”

Page 6: Benefits of Hypermedia API

7

IMMEDIATE BENEFITS Explorable API Inline documentation Simple client logic

Page 7: Benefits of Hypermedia API

8

“BILLBOARD” ENDPOINT

GET /api200 Ok<links><link rel=“…” href=“…”/><link rel=“…” href=“…”/>...</links>

Page 8: Benefits of Hypermedia API

9

LINKED DATA PRINCIPLES

1.Use URIs as names for things2.Use HTTP URIs so that people can look up those

names.3.When someone looks up a URI, provide useful

information, using the standards4.Include links to other URIs so that they can discover

more things.

Tim Berners-Lee (2006) http://www.w3.org/DesignIssues/LinkedData.html

Page 9: Benefits of Hypermedia API

10

EXAMPLE: CHECK BANK ACCOUNT BALANCEEXPLORABLE API + INLINE DOCUMENTATION GET /account/12345

200 OK <?xml version="1.0"?> <account> <account_number>12345</account_number> <link rel=“self” href=“/account/12345” /><balance currency="usd">100.00</balance> <link rel=“http://bank.org/rel/first-subscriber" href="/customer/123" /> <link rel=“http://bank.org/rel/subscribers" href="/account/12345/subscriber" />

<link rel="http://bank.org/rel/deposit" href="/account/12345/deposit" /> <link rel="http://bank.org/rel/withdraw" href="/account/12345/withdraw" /> <link rel="http://bank.org/rel/transfer" href="/account/12345/transfer" /> <link rel="http://bank.org/rel/close" href="/account/12345/close" /> </account> Semantic

and documentat

ion

Use URI as names

Explorable

Page 10: Benefits of Hypermedia API

11

CLIENT SIMPLICITYCoupled to implementation

res = GET /account/123 If enough-funds() then msg = build-withdraw-message()

url = build-url-from-template()

POST msg @ url Endif

Hypermedia-driven res = GET /account/123 If res.hasLink(“withdraw”) then

msg = build-withdraw-message()

POST msg @ res.link(“withdraw”)

EndifNeeds to know URL template

Business logic spills

out to client

Server handles Business

logic

Server manages

URL structure

VS

Page 11: Benefits of Hypermedia API

12

FLEXIBILITY & EVOLUTION Server takes ownership of URL Offloading content Upgrading

Page 12: Benefits of Hypermedia API

13

EXAMPLE: CHECK BANK ACCOUNT BALANCESERVER MODIFIES URL STRUCTURE GET /account/12345

200 OK <?xml version="1.0"?> <account> <account_number>12345</account_number> <link rel=“self” href=“/account/12345” /><balance currency="usd">100.00</balance> <link rel=“http://bank.org/rel/first-subscriber" href=“/crm/123?role=customer" /> <link rel=“http://bank.org/rel/subscribers" href="/account/12345/subscriber" />

<link rel="http://bank.org/rel/deposit" href="/account/12345/deposit" /> <link rel="http://bank.org/rel/withdraw" href="/account/12345/withdraw" /> <link rel="http://bank.org/rel/transfer" href="/account/12345/transfer" /> <link rel="http://bank.org/rel/close" href="/account/12345/close" /> </account>

New URL; no problem client just follows it

Page 13: Benefits of Hypermedia API

14

EXAMPLE: CHECK BANK ACCOUNT BALANCECONTENT OFFLOADING GET /account/12345

200 OK <?xml version="1.0"?> <account> <account_number>12345</account_number> <link rel=“self” href=“/account/12345” /><balance currency="usd">100.00</balance> <link rel=“http://bank.org/rel/first-subscriber" href=“http://one-crm.com/api/tenant/bankABC/prospect/754" />

<link rel=“http://bank.org/rel/pricing" href=“http://bankABC.cdn.akamai.com/static/pricing" />

...</account>

Content offloaded to 3rd party providers

Page 14: Benefits of Hypermedia API

15

EXAMPLE: CHECK BANK ACCOUNT BALANCESERVER UPGRADE GET /account/12345

200 OK <?xml version="1.0"?> <account> <account_number>12345</account_number> <link rel=“self” href=“/account/12345” /><balance currency="usd">100.00</balance> <link rel=“http://bank.org/rel/first-subscriber" href=“http://one-crm.com/api/tenant/bankABC/prospect/754" />

<link rel=“http://bank.org/rel/pricing" href=“http://bankABC.cdn.akamai.com/static/pricing" /> <link rel="http://bank.org/rel/deposit" href="/account/12345/deposit" type=“application/vnd.bankABC.deposit.v2+xml, application/vnd.bankABC.deposit+xml” />

...</account>

New relationship; only V2 clients

will know it

New media type accepted; only V2 clients will know it

Page 15: Benefits of Hypermedia API

16

CLOSINGS

Page 16: Benefits of Hypermedia API

1. Adhere to the hypermedia constraint

2. Aim for a “billboard” API

3. Decouple client and server

Page 17: Benefits of Hypermedia API

REFERENCES

Page 18: Benefits of Hypermedia API

Jørn Wildt (2013) Selling the benefits of hypermedia APIs. http://soabits.blogspot.no/2013/12/selling-benefits-of-hypermedia.html

David (2012) Getting hyper about hypermedia APIs. https://signalvnoise.com/posts/3373-getting-hyper-about-hypermedia-apis

“Architectural Styles and the Design of Network-based Software Architectures”, PhD Thesis (2000), Roy Thomas Fielding. http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm

Leonard Richardson, Mike Amundsen, RESTful web APIs. O’Reily Media. ISBN: 1449358063