Joost Cassee
joost@cassee.net
@jcassee
jcassee.com
Nextbuild, 30 May 2015
Press down / right to advance slides
"Monitor and encourage compliance with legislation [for safe] human environment and transport."
REST as it should be™
An extremely personal view on REST
URI
http://example.com/ship/9334026
"An entity"
{
"name": "VOS PROMINENCE",
"imo": 9334026,
"type": "cargo"
}
Media Type
application/json
Profile
http://example.com/profiles/ship
"It is a ship"
The resource identified by http://example.com/ship/9334026
{
"name": "VOS PROMINENCE",
"imo": 9334026,
"type": "cargo"
}
and is represented as application/json by
has profile http://example.com/profiles/ship
A resource identified by a http/https URL
can be manipulated using HTTP methods
GET
PUT
DELETE
POST
(PATCH
Retreive a representation
Store a representation
Delete a resource
"Process" a representation
Update a resource)
}
idempotent
Sending
{
"name": "VOS PROMINENCE",
"imo": 9334026,
"type": "cargo"
}
results in response
GET http://example.com/ship/9334026
Accept: application/json
PUT http://example.com/ship/9334026
Content-Type: application/json
{
"name": "COSCO BREMERHAVEN",
"imo": 9334026,
"type": "cargo"
}
results in changing the name of the ship
Sending
... for the most part
Expose business logic as state manipulation
Relation
http://example.com/relations/owner
"It has an owner"
The resource identified by http://example.com/ship/9334026
to the resource identified by http://example.com/company/3342
has relation http://example.com/relations/owner
Hypermedia Application Language
application/hal+json
{
"name": "VOS PROMINENCE",
"imo": 9334026,
"type": "cargo",
...
"_links": {
"self": {
"href": "http://example.com/ship/9334026"
},
"profile": {
"href": "http://example.com/profiles/ship"
},
"http://example.com/relations/owner": {
"href": "http://example.com/company/3342"
}
},
...
...
"_embedded": {
"http://example.com/relations/owner": {
"name": "Vroon B.V."
"_links": {
"self": {
"href": "http://example.com/company/3342"
},
"profile": {
"href": "http://example.com/profiles/company"
}
}
}
}
}
{
"_links" : {
"http://example.com/relations/profile-image" : {
"href" : "http://example.com/user/23/profile-image"
}
}
}
{
"profileImageUri": "http://example.com/images/bunny.jpg"
}
{
...
"_links" : {
...
"http://example.com/relations/owner" : {
"href" : "http://example.com/company/3342",
"deprecation": "http://example.com/docs/deprecated/owner.html"
},
"http://example.com/relations/ownership" : {
"href" : "http://example.com/ship/9334026/ownership/3"
}
}
}
Operate on local data, keep it synchronized
for pages, code and assets
index.html
<html manifest="offline.appcache">
offline.manifest
CACHE MANIFEST
# v1 2015-05-30
index.html
styles/main.css
images/logo.png
scripts/app.js
NETWORK:
*
for data
var db;
var request = indexedDB.open("MyDatabase");
request.onsuccess = function(event) {
db = event.target.result;
};
var transaction = db.transaction("customers");
var objectStore = transaction.objectStore("customers");
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
console.log(cursor.key + ": " + cursor.value.name);
cursor.continue();
}
};
resources:
uri -> representation
dirty:
uri
resourcecache:
GET
PUT
DELETE flow similar to PUT
POST
PUT all dirty resources
Reissue all stored POST requests in order
Keep related resources synchronized
https://github.com/jmesnil/stomp-websocket
Simple pub/sub over websockets
SUBSCRIBE
id:0
destination:http://example.com/company/3342/ships
MESSAGE
subscription:0
message-id:007
destination:http://example.com/company/3342/ships
content-type:application/hal+json
{
"total": 5,
...
Code will be available at https://github.com/jcassee
http://en.wikipedia.org/wiki/File:FCC_and_CE.jpg
https://www.flickr.com/photos/tranbc/6944672554
http://commons.wikimedia.org/wiki/File:Air_Malta_Pre_Flight_Inspection_Airbus_A320.jpg
http://commons.wikimedia.org/wiki/File:Fireworks_PDX_1.jpg
http://commons.wikimedia.org/wiki/File:Nationaal_Park_De_Biesbosch.jpg
http://jakarta.usembassy.gov/pr_09222010.html
http://commons.wikimedia.org/wiki/File:Een_%28oud%29_voorbeeld_van_een_vergunnning_2013-05-09_21-53.jpeg
http://commons.wikimedia.org/wiki/File:TsingTao_Express_IMO_9320702,_Port_of_Rotterdam,_Holland,_06JAN2009_pic1.JPG
http://commons.wikimedia.org/wiki/File:Pet_dog_fetching_sticks_in_Wales-3April2010.jpg