fluent-siren-client
Fluent client for Siren Hyper Media APIs
Fetches a Siren object using the provided href and request function, and parses it into a node-siren-parser Entity. Configures the Entity in such a way that uri links can be followed, and actions can be performed. Result of following a link is another fluent Entity.
Installation
Install from NPM:
npm install fluent-siren-client
Usage
const client = requestFn; // async requestFn(uri, method, fieldValues)const entity = await clientstart'http://api.example.com';const linkedEntity = await entity;const subEntity = await entity;const actionResult = await entity;const actionResultStatusCode = actionResultstatusCode;
Setup
Sample requestFn
using request-promise
library
const rp = ; { const params = defaults: headers: Authorization: `Bearer ` // inject authorization token json: true resolveWithFullResponse: true event: true ; const options = uri method ; if method === 'GET' optionsqs = fieldValues; else optionsbody = fieldValues; const request = ; const response = await ; const body headers = response; return body contentType: headers'content-type' response ;}