jsonapi.js
jsonapi.js is a Javascript implement of jsonapi 1.0 version.
Installation
Install jsonapi.js by NPM
npm install jsonapi.js
Install jsonapi.js by Bower
bower install jsonapi.js
Usage
var jsonapi = require('jsonapi.js');
var Pool = jsonapi.Pool;
var Resource = jsonapi.Resource;
var Relationship = jsonapi.Relationship;
var pool = new Pool();
pool.addRemote('foo', '/api/foo');
pool.fetch('foo');
pool.fetch('foo', 1);
pool.create('foo', {
attributes: {
content: 'foo'
}
});
pool.update('foo', 1, {
attributes: {
'content': 'bar'
}
});
pool.remove('foo', 1);
var toOneRelationship = new Relationship({
data: null
});
pool.replaceLinkage(toOneRelationship, {
type: 'baz',
id: 1
});
pool.replaceLinkage(toOneRelationship, null);
var toManyRelationship = new Relationship({
data: []
});
pool.replaceLinkage(toManyRelationship, [{
type: 'bar',
id: 1
}]);
pool.addLinkage(toManyRelationship, [{
type: 'bar',
id: 1
}]);
pool.removeLinkage(toManyRelationship, [{
type: 'bar',
id: 1
}]);
Contributing
Install Dependencies: gulp
npm install -g gulp
watch
gulp watch
build
gulp build
test
gulp test