Super-Siren
Description
SIREN Hypermedia client library which process SIREN HTTP responses into immutable SIREN representations utilizing superagent for the underlying HTTP requests. All superagent requests are wrapped with superagent-promise which exposes Bluebird promises for processing http requests.
SIREN models within this library are created using Immutable.js Records with properties constructed using Immutable maps, sets and lists.
Links
Siren-Crawler - Siren Crawler is a generic Siren browser that utilizes super-siren for requesting and parsing all SIREN messages. Siren Crawler is implemented as a single page javascript application utilizing React and flux.
Getting Started
Install super-siren
using npm.
npm install super-siren
Then require super-siren from any JavaScript module:
let Siren = ;
To get started provide the SIREN billboard URL to the static get method.
let Siren = ; Siren ;
super-siren automatically registers a SIREN parser for all http requests made through super-siren. Any HTTP response which specifies a content type of application/vnd.siren+json
. All other content-types will fall back to the default superagent parsers.
Setting Global Headers
super-siren allows you to set global headers for all requests made through super-siren. Super-siren will automatically add an Accepts header requesting application/vnd.siren+json
, so you don't have to worry about adding that one. To add a custom header simply do the following:
let Siren = ; SirenClient;
To then later remove the header you can simply:
SirenClient;
Helpers
super-siren provides helper functions to assist with navigating through SIREN responses. This allows for using a fluent syntax to navigate from a base SIREN URL through it's available links, entities and actions.
For example if you had a base SIREN entity at http://example-siren/api
and wanted to follow through a link at rel favorites
and wanted to perform an action named add-favorite
in order to add a favorite you could write the following:
let Siren = ;let follow = SirenHelperfollow;let performAction = SirenHelperperformAction; Siren // the data opts are optional ;
SIREN structure
let Siren = ;Siren ;
SIREN navigation helpers
let Siren = ; Siren ;