1.0.13 • Published 8 years ago
sails-linking-models v1.0.13
sails-linking-models
Description
Ability to generate hateoas-compatible links to actions (read/update/delete) on model items.
Install
$ npm install sails-linking-models
Usage
Mixin with your sails model declarations (in /api/models/YOUR_MODEL.js) like so:
var linkingModels = require('sails-linking-models');
var model = {
// Your model declaration here
};
module.exports = linkingModels.mixin(model);
Inside your model declaration you can generate links by passing in a controller name and the reverseRouteService function, and, optionally, an array of controller actions to link to:
var actions = ['action1', 'action2'];
var links = this.modelLinks(controllerName, reverseRouteService, actions);
Actions will default to the blueprint actions if none is passed in:
['findOne', 'update', 'destroy']
Tests
$ npm install
$ npm test