![Page 1: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/1.jpg)
HATEOAS 101An Opinionated Introduction
Brian Mulloy@landlessness
Apigee@apigee
![Page 2: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/2.jpg)
groups.google.com/group/api-craft
![Page 3: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/3.jpg)
youtube.com/apigee
![Page 4: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/4.jpg)
IRC Channel#api-crafton freenode
New!
![Page 5: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/5.jpg)
WARNING: The author may betray a bias against the application of REST constraints to web APIs.
![Page 6: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/6.jpg)
What is HATEOAS?
![Page 7: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/7.jpg)
![Page 8: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/8.jpg)
Hypermedia As The Engine Of Application State
![Page 9: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/9.jpg)
Let’s put HATEOAS in the full context of REST.
![Page 10: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/10.jpg)
The Constraints of REST
1. Client-server2. Stateless server3. Cache4. Uniform interface
a. Identification of resourcesb. Manipulation of resources through representationsc. Self-descriptive messagesd. Hypermedia as the engine of application state
5. Layered System6. Code-On-Demand (optional)
![Page 11: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/11.jpg)
Let’s break it down.
![Page 12: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/12.jpg)
The first three constraints…
![Page 13: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/13.jpg)
1. Client-server2. Stateless server3. Cache
![Page 14: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/14.jpg)
…give us the client-cache-stateless-server web architecture.
![Page 15: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/15.jpg)
statelessserver
client
cache
client
cache
Each request must contain
all information. No stored context on the
server.
Client has the right to reuse
response data.
![Page 16: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/16.jpg)
(we’ll come back to the 4th constraint)
![Page 17: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/17.jpg)
The 5th constraint, Layered System, lets us add features like a gateway, load balancer and firewall.
![Page 18: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/18.jpg)
client
Each layer cannot "see" beyond it’s
immediate neighbor.
statelessserver
statelessserver
statelessserver
loadbalancer
gatewayfirewall
Each layer provides services to it’s neighbors.
Layers can encapsulate legacy services & protect new services from legacy
clients.
![Page 19: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/19.jpg)
The optional 6th constraint, Code-on-Demand, allows the client to request code from the server & execute it.
![Page 20: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/20.jpg)
statelessserver
client
Better user-perceived performance and
efficiency
Add features to a deployed client, which provides for improved
extensibility and configurability
code
![Page 21: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/21.jpg)
Now lets tackle the 4 parts of the 4th constraint,Uniform Interface
![Page 22: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/22.jpg)
With help from the Twitter UI.
![Page 23: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/23.jpg)
a. Resource Identifier identifies the particular resource involved in an interaction between components.
![Page 24: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/24.jpg)
http://twitter.com/#!/jack/status/20
![Page 25: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/25.jpg)
b. Resource Representation represents the state of a resource for transfer between components.
![Page 26: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/26.jpg)
<!DOCTYPE html><html data-nav-highlight-class-name="highlight-global-nav-home"> <head> <title>Twitter</title><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta charset="utf-8" /> <meta name="description" content="Instantly connect to what's most important to you. Follow your friends, experts, favorite celebrities, and breaking news." /> <link rel="dns-prefetch" href="http://a0.twimg.com"/> <link rel="dns-prefetch" href="http://api.twitter.com"/><script type="text/javascript" charset="utf-8"> document.domain = 'twitter.com'; // this will be copied to twttr.appStartTime once our JS has started up document.startTime = new Date().getTime(); var twttr = {}; twttr.versionName = 'phoenix'; twttr.isT1 = true; twttr.didPingKeynote = false; twttr.keynoteTTFTPing = function() { if (!twttr.didPingKeynote && window.location.href.indexOf('keynoteTest') > 0) { var image = document.createElement('img'); image.src = '/images/keynote.gif'; twttr.didPingKeynote = true; } } window.console||function(){var a=["log","debug","info","warn","error","assert","dir","dirxml","group","groupEnd","time","timeEnd","count","trace","profile","profileEnd"];window.console={};for(var b=0;b<a.length;++b)window.console[a[b]]=function(){}}();</script>…
![Page 27: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/27.jpg)
c. Self-descriptive messages contains all the information necessary to complete transformations.
![Page 28: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/28.jpg)
GET /#!/jack/status/20 HTTP/1.1 User-Agent: Chrome/18.0.1025.11Host: twitter.comAccept: text/html
![Page 29: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/29.jpg)
d. Hypermedia as the engine of application state
![Page 30: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/30.jpg)
![Page 31: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/31.jpg)
state
state
state
state
state
transition transition
transitiontransition
![Page 32: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/32.jpg)
The name ‘Representational State Transfer’ is intended to evoke an image of how a well-designed Web application behaves: a network of web pages (a virtual state-machine), where the user progresses through the application by selecting links (state transitions), resulting in the next page (representing the next state of the application) being transferred to the user and rendered for their use.
“
-Roy FieldingArchitectural Styles and the
Design of Network-based Software ArchitecturesChapter 6
![Page 33: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/33.jpg)
States are web pages.
![Page 34: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/34.jpg)
Transitions are hyperlinks.
![Page 35: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/35.jpg)
The key to implementing HATEOAS is pretty simple
![Page 36: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/36.jpg)
In each response message include the links for the next request message.
![Page 37: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/37.jpg)
AppUser UI Server
AppDeveloper
REST Interface
BrowserApp
![Page 38: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/38.jpg)
![Page 39: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/39.jpg)
home connect discover search my profile direct messages
lists
help
google: jack’s first
tweet
keyboard shortcuts
settings
new tweet@jackFollow @jackadd or remove
from listsblock @jack
turn off retweets
retweet
reply to @jack
favorite about
tweet to @jack
sign outreport @jack
for spam
![Page 40: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/40.jpg)
1 transition in, 32 transitions out
![Page 41: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/41.jpg)
A quick aside
![Page 42: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/42.jpg)
The three greatest inventions of all time are:
![Page 43: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/43.jpg)
Bicycles
![Page 44: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/44.jpg)
Beer
![Page 45: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/45.jpg)
The Hyperlink
![Page 46: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/46.jpg)
With a browser I can start at http://twitter.com
![Page 47: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/47.jpg)
And navigate my way through every state of the entire Twitter application.
![Page 48: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/48.jpg)
It’s amazing!
![Page 49: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/49.jpg)
HATEOAS is not scary.
![Page 50: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/50.jpg)
![Page 51: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/51.jpg)
HATEOAS is the key constraint that makes surfing the web with a browser possible.
![Page 52: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/52.jpg)
Let’s look at HATEOAS and APIs
![Page 53: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/53.jpg)
With help from the Twitter API.
![Page 54: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/54.jpg)
GET /1/statuses/show/20.jsonHTTP/1.1Host: api.twitter.com
![Page 55: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/55.jpg)
{ "created_at": "Tue Mar 21 20:50:14 +0000 2006", "id": 20, "id_str": "20",
"text": "just setting up my twttr", "source": "web", "truncated": false, "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "in_reply_to_screen_name": null, "user": { "id": 12, "id_str": "12",
"name": "Jack Dorsey", "screen_name": "jack", "location": "San Francisco", "description": "Executive Chairman of Twitter, CEO of Square, a founder of both.", "url": null, "protected": false, "followers_count": 1935426, "friends_count": 1148, "listed_count": 17312, "created_at": "Tue Mar 21 20:50:14 +0000 2006", "favourites_count": 988, "utc_offset": -28800, "time_zone": "Pacific Time (US & Canada)", "geo_enabled": true, "verified": true, "statuses_count": 10894, "lang": "en", "contributors_enabled": true, "is_translator": false, "profile_background_color": "EBEBEB", "profile_background_image_url": "http://a0.twimg.com/images/themes/theme7/bg.gif", "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme7/bg.gif", "profile_background_tile": false, "profile_image_url": "http://a0.twimg.com/profile_images/1563216547/image_normal.jpg", "profile_image_url_https": "https://si0.twimg.com/profile_images/1563216547/image_normal.jpg", "profile_link_color": "990000", "profile_sidebar_border_color": "DFDFDF", "profile_sidebar_fill_color": "F3F3F3", "profile_text_color": "333333", "profile_use_background_image": true, "show_all_inline_media": true, "default_profile": false, "default_profile_image": false, "following": null, "follow_request_sent": null, "notifications": null }, "geo": null, "coordinates": null, "place": null, "contributors": null, "retweet_count": 5973, "favorited": false, "retweeted": false}
![Page 56: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/56.jpg)
Uh oh. There are zero hyperlinks.
![Page 57: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/57.jpg)
How many should there be to respect the HATEOAS constraint?
![Page 58: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/58.jpg)
At least one.
![Page 59: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/59.jpg)
{ "created_at": "Tue Mar 21 20:50:14 +0000 2006", "id": 20, "id_str": "20",
"text": "just setting up my twttr", "source": "web", "truncated": false, "in_reply_to_status_id": null, "in_reply_to_status_id_str": null, "in_reply_to_user_id": null, "in_reply_to_user_id_str": null, "in_reply_to_screen_name": null, "user": { "id": 12,
"link": ”http://api.twitter.com/1/users/show.json?user_id=12", "id_str": "12",
"name": "Jack Dorsey", "screen_name": "jack", "location": "San Francisco", "description": "Executive Chairman of Twitter, CEO of Square, a founder of both.", "url": null, "protected": false, "followers_count": 1935426, "friends_count": 1148, "listed_count": 17312, "created_at": "Tue Mar 21 20:50:14 +0000 2006", "favourites_count": 988, "utc_offset": -28800, "time_zone": "Pacific Time (US & Canada)", "geo_enabled": true, "verified": true, "statuses_count": 10894, "lang": "en", "contributors_enabled": true, "is_translator": false, "profile_background_color": "EBEBEB", "profile_background_image_url": "http://a0.twimg.com/images/themes/theme7/bg.gif", "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme7/bg.gif", "profile_background_tile": false, "profile_image_url": "http://a0.twimg.com/profile_images/1563216547/image_normal.jpg", "profile_image_url_https": "https://si0.twimg.com/profile_images/1563216547/image_normal.jpg", "profile_link_color": "990000", "profile_sidebar_border_color": "DFDFDF", "profile_sidebar_fill_color": "F3F3F3", "profile_text_color": "333333", "profile_use_background_image": true, "show_all_inline_media": true, "default_profile": false, "default_profile_image": false, "following": null, "follow_request_sent": null, "notifications": null }, "geo": null, "coordinates": null, "place": null, "contributors": null, "retweet_count": 5973, "favorited": false, "retweeted": false}
![Page 60: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/60.jpg)
A few questions.
![Page 61: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/61.jpg)
Now are we HATEOAS compliant?
![Page 62: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/62.jpg)
If we add another link does it change the consuming application’s state machine?
![Page 63: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/63.jpg)
Is it ok for the developer to ignore included links?
![Page 64: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/64.jpg)
Can the developer add out-of-band links to her app?
![Page 65: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/65.jpg)
What happens when an app relies on multiple APIs? Where is the state machine?
![Page 66: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/66.jpg)
If the Twitter API had complied with HATEOAS
![Page 67: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/67.jpg)
When Loren Brichter
![Page 68: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/68.jpg)
![Page 69: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/69.jpg)
Created Tweetie
![Page 70: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/70.jpg)
![Page 71: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/71.jpg)
Would he have been able to decide which user actions to include in his design?
![Page 72: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/72.jpg)
![Page 73: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/73.jpg)
Or would those decisions have been driven by the links in the response from the Twitter API?
![Page 74: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/74.jpg)
![Page 75: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/75.jpg)
![Page 76: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/76.jpg)
Nearly all popular web UIs adhere to HATEOAS.
![Page 77: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/77.jpg)
Nearly all popular web APIs violate HATEOAS.
![Page 78: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/78.jpg)
Why?
![Page 79: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/79.jpg)
Let’s examine the two worlds.
![Page 80: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/80.jpg)
AppUser UI Server
AppDeveloper
REST Interface
BrowserApp
I decide where to click, aka
change state.
I craft the user experience, aka state diagram.
I guarantee hypermedia is engine of app
state
![Page 81: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/81.jpg)
The person who crafts the experience (state diagram) and the app user have the REST interface between them.
![Page 82: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/82.jpg)
And the hypermedia links are given directly to the app user at runtime.
![Page 83: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/83.jpg)
So the hypermedia in each response message is genuinely the engine of application state.
![Page 84: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/84.jpg)
This pattern is not limited to user interfaces.
![Page 85: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/85.jpg)
We see the same pattern for syndication feeds.
![Page 86: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/86.jpg)
Feed ReaderApp
AppUser
FeedServer
ContentPublisher
REST Interface
I decide where to click, aka
change state.
I craft stories, categories & related
media, aka state diagram.
I guarantee hypermedia is engine of app
state
![Page 87: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/87.jpg)
But the world of apps and web APIs seems different.
![Page 88: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/88.jpg)
App 1 AppDeveloper 1
AppUser
API Server
Interface
App 2 AppDeveloper 2
App 3 AppDeveloper 3
![Page 89: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/89.jpg)
App 1 AppDeveloper 1
AppUser
API Server
Interface
App 2 AppDeveloper 2
App 3 AppDeveloper 3
I decide where to click, aka
change state.
I craft the user experience, aka state diagram.
I get no HATEOAS respect.
I craft the user experience, aka state diagram.
I craft the user experience, aka state diagram.
![Page 90: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/90.jpg)
The person who crafts the experience (state machine) and the app user do not have the REST interface between them.
![Page 91: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/91.jpg)
And the hypermedia links are not given directly to the app user at runtime.
![Page 92: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/92.jpg)
Instead, the hypermedia are given to the developer at design time.
![Page 93: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/93.jpg)
And the developer decides which states are possible for the app user at runtime.
![Page 94: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/94.jpg)
We need a Yoda moment.
![Page 95: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/95.jpg)
![Page 96: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/96.jpg)
You must unlearn what you have learned.“-Yoda
![Page 97: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/97.jpg)
I used to call the world of popular, non-HATEOAS, non-SOAP web APIs, Pragmatic REST.
![Page 98: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/98.jpg)
Oops.
![Page 99: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/99.jpg)
How do we answer the questions many API teams are asking
![Page 100: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/100.jpg)
1. Should we go down the HATEOAS path?
![Page 101: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/101.jpg)
As a practical matter, for many teams that previous question is the same as the next question.
![Page 102: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/102.jpg)
2. Should we include links in our responses?
![Page 103: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/103.jpg)
But they have different answers.
![Page 104: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/104.jpg)
1. For an API to be HATEOAS-compliant it requires a client app that is also HATEOAS-compliant.
![Page 105: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/105.jpg)
A user-interface app driven by web APIs would be akin to a feed reader for syndicated content.
![Page 106: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/106.jpg)
But designed to handle generic web APIs.
![Page 107: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/107.jpg)
RESTful APIClient App
AppUser
APIDeveloper
REST Interface
API Server
?
I decide where to click, aka
change state.
I craft a system of interrelated resources,
aka state diagram.
I guarantee hypermedia is engine of app
state
![Page 108: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/108.jpg)
Special thanks to @elasticpath for this metaphor.
![Page 109: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/109.jpg)
There are interesting non-UI applications as well.
![Page 110: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/110.jpg)
However, the style does not assume that all applications are browsers. In fact, the application details are hidden from the server by the generic connector interface, and thus a user agent could equally be an automated robot performing information retrieval for an indexing service, a personal agent looking for data that matches certain criteria, or a maintenance spider busy patrolling the information for broken references or modified content [39].
“
-Roy FieldingArchitectural Styles and the
Design of Network-based Software ArchitecturesChapter 5
![Page 111: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/111.jpg)
If you’re not going down the HATEOAS client path, should you include links anyway?
![Page 112: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/112.jpg)
2. If you think including links in the API response will be helpful for developers at design time, then go for it.
![Page 113: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/113.jpg)
![Page 114: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/114.jpg)
But I wouldn’t call it HATEOAS because those links are probably not the engine of application state for the app user at run time.
![Page 115: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/115.jpg)
If the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. Period. Is there some broken manual somewhere that needs to be fixed?
“
-Roy Fielding“REST APIs must be hypertext-driven”Untangled: Musings of Roy T. Fielding
![Page 116: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/116.jpg)
![Page 117: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/117.jpg)
Here’s a call to action
![Page 118: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/118.jpg)
We know what REST with the HATEOAS constraint is and isn’t.
![Page 119: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/119.jpg)
We know what SOAP is and isn’t.
![Page 120: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/120.jpg)
But we don’t have an intellectual framework for the way so many popular apps and web APIs work today.
![Page 121: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/121.jpg)
We need a really smart person
![Page 122: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/122.jpg)
Who cares about web APIs
![Page 123: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/123.jpg)
To examine the constraints of REST
![Page 124: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/124.jpg)
The Constraints of REST
1. Client-server2. Stateless server3. Cache4. Uniform interface
a. Identification of resourcesb. Manipulation of resources through representationsc. Self-descriptive messagesd. Hypermedia as the engine of application state
5. Layered System6. Code-On-Demand (optional) Applicable to APIs
at all?
What are the
HATEOAS app
characteristics?
If the API drives app state, are we still
respecting client-server separation?
![Page 125: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/125.jpg)
While keeping in mind how custom apps are built by people using web APIs
![Page 126: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/126.jpg)
App 1 AppDeveloper 1
AppUser
API Server
Interface
App 2 AppDeveloper 2
App 3 AppDeveloper 3
![Page 127: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/127.jpg)
To give us a new foundation
![Page 128: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/128.jpg)
The Constraints of ____
1. ???2. ???3. ???4. ???5. ???6. ???
![Page 129: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/129.jpg)
So that we will have a better shared idea of what we’re really doing
![Page 130: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/130.jpg)
We will be able to communicate more effectively
![Page 131: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/131.jpg)
And we will be able to create more value for the planet and the people on it.
![Page 132: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/132.jpg)
![Page 133: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/133.jpg)
But please choose a nice, pronounceable acronym.
![Page 134: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/134.jpg)
![Page 135: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/135.jpg)
Further Exploring
• http://steveklabnik.com/• http://pinboard.in/u:earth2marsh/t:hateoas/• http://www.ics.uci.edu/~fielding/pubs/dissert
ation/top.htm
• http://martinfowler.com/articles/richardsonMaturityModel.html
• http://timelessrepo.com/haters-gonna-hateoas
![Page 136: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/136.jpg)
Questions?
![Page 137: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/137.jpg)
THANK YOUSubscribe to API webinars at:
youtube.com/apigee
![Page 138: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/138.jpg)
THANK YOUIRC#api-crafton freenode
![Page 139: HATEOAS 101 - Opinionated Introduction to a REST API Style](https://reader033.vdocuments.us/reader033/viewer/2022061300/54c65af84a795940598b4582/html5/thumbnails/139.jpg)
THANK YOUQuestions and ideas to:
groups.google.com/group/api-craft