res.json to accept an array of HATEOAS links to be appended to the output JSON object.
npm install --save express-hateoas-links
// send person object with HATEOAS links addedres;
Typical use case
The example below adds a self & create link to a JSON schema used to create a person. This allows the consuming application to understand what properties are required to create a Person and the destination URL to post to, removing the need for the application to hard code API links.
var express = ;var app = ;var hateoasLinker = ;// replace standard express res.json with the new versionapp;// standard express routeapp;// express route to process the person creationapp;
You can set
req.disableHATEOAS = false within a controller or pass
hateoas=false via the QueryString to disable HATEOAS links.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
You can run the unit tests by changing directory into the express-hateoas-links director within your node_modules folder, and run the following commands:
npm install // install modules dev dependenciesnpm test // run unit tests
Star the repo
Please star the repo if you find this useful as it helps us priorities which open source issues to tackle first.
For change-log, check releases.