
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
jsonapi.js
Advanced tools
jsonapi.js is a Javascript implement of jsonapi 1.0 version.
Install jsonapi.js by NPM
npm install jsonapi.js
Install jsonapi.js by Bower
bower install jsonapi.js
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');
/*=============================
Fetching Data
http://jsonapi.org/format/#fetching
=============================*/
/*
GET /api/foo HTTP/1.1
Accept: application/vnd.api+json
*/
pool.fetch('foo');
/*
GET /api/foo/1 HTTP/1.1
Accept: application/vnd.api+json
*/
pool.fetch('foo', 1);
/*=============================
Creating, Updating and Deleting Resources
http://jsonapi.org/format/#crud
=============================*/
/*
POST /api/foo HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": {
"type": "foo",
"attributes": {
"content": "foo"
}
}
}
*/
pool.create('foo', {
attributes: {
content: 'foo'
}
});
/*
PATCH /api/foo/1 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": {
"type": "foo",
"id": 1,
"attributes": {
"content": "bar"
}
}
}
*/
pool.update('foo', 1, {
attributes: {
'content': 'bar'
}
});
/*
DELETE /api/foo/1 HTTP/1.1
Accept: application/vnd.api+json
*/
pool.remove('foo', 1);
/*=============================
Update To-One Relationships
http://jsonapi.org/format/#crud-updating-to-one-relationships
=============================*/
var toOneRelationship = new Relationship({
data: null
});
/*
PATCH /api/foo/1/relationships/baz HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": {
type: 'baz',
id: 1
}
}
*/
pool.replaceLinkage(toOneRelationship, {
type: 'baz',
id: 1
});
/*
PATCH /api/foo/1/relationships/baz HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": null
}
*/
pool.replaceLinkage(toOneRelationship, null);
/*=============================
Update To-Many Relationships
http://jsonapi.org/format/#crud-updating-to-many-relationships
=============================*/
var toManyRelationship = new Relationship({
data: []
});
/*
PATCH /api/foo/1/relationships/bar HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": [{
type: 'bar',
id: 1
}]
}
*/
pool.replaceLinkage(toManyRelationship, [{
type: 'bar',
id: 1
}]);
/*
POST /api/foo/1/relationships/bar HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": [{
type: 'bar',
id: 1
}]
}
*/
pool.addLinkage(toManyRelationship, [{
type: 'bar',
id: 1
}]);
/*
DELETE /api/foo/1/relationships/bar HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json
{
"data": [{
type: 'bar',
id: 1
}]
}
*/
pool.removeLinkage(toManyRelationship, [{
type: 'bar',
id: 1
}]);
Install Dependencies: gulp
npm install -g gulp
watch
gulp watch
build
gulp build
test
gulp test
FAQs
Javascript implementation of JSONAPI
The npm package jsonapi.js receives a total of 6 weekly downloads. As such, jsonapi.js popularity was classified as not popular.
We found that jsonapi.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.