
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
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 0 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.