The code for my talk Hypermedia in the Shadow of the Death Star.
- Install dependencies by running
npm install
from both theserver
andclient
folders - Start the server by running
npm start
in theserver
folder - Start the Node.js REPL from the
client
folder - Run
var g = require("./").silent
- Now
g
is a object with functions to manipulate the gameto(url, mediaType)
: makes a GET tourl
with anAccept
header (both the URL and media types are then re-used for further requests made to relative URL)body()
,json()
,yaml()
: prints the body of the last received responselook()
: prints the description of the current location (if the last received response if of typevnd.siren
orx.star
only)links()
,actions()
,controls()
: respectively prints the links, actions, both links and actions available at the current location (if the last received response if of typevnd.siren
orx.star
only)go(linkIndex)
: makes a GET request to thehref
of the link at the indexlinkIndex
(if the last received response if of typevnd.siren
orx.star
only)do(actionName, params)
: makes a request as described by the action whichname
isactionNameOrIndex
(if the last received response if of typevnd.siren
orx.star
only)follow()
: makes a GET request to the URL given by theLocation
headerauth(userid, password)
: re-makes the last request with basic authenticationoptions()
: makes an OPTIONS request to the last URL usedget(mediaType)
: makes a GET request at the last URL used with anAccept
header (the media type will then be re-used for further requests)delete()
: makes a DELETE request the last URL usedprev()
,next()
: navigates partial resourcesback()
: makes a GET request to the next to last visited URL
- Start by calling
g.to("http://localhost:3000", "application/x.star+json")
then follow the links ;)
As of yet, the server is stateful and can only handle one game at a time. You must restart the server everytime you want to start a new game.
The original idea for the talk was imagined by Einar W. Høst. With his permission, my talk re-uses the mechanics and topics of his, but the code was written from scratch without any knowlegde of the original, and the theme and scenario are completely different.
This code was written for me to learn how to implement Hypermedia APIs, which is something that I had never done before. It is exploratory code. There was also a very hard deadline for it to be working for the date of the presentation. Therefore, I would not qualify it as being of quality, or even good. It work well enough for the purpose of the talk, but it is not well-designed, robust, duplication-free.
It can not be a reference on how to implement Hypermedia APIs.
- Immutable ressources. Still have to explore that idea but the mutability in the current version makes it horrendously complex.
- Stateless server. No-brainer. Was traded off for development speed.
- deploy it!
- links to images and sounds
- support for
Accept-Language
- 405 instead of 404 when the resource exists but the method is not allowed (this is an issue with Express, but it can be worked around)