A JSON data object Express router with PATCH support.
npm install --save @kjots/express-json-data
import express from 'express';
import expressJsonData from '@kjots/express-json-data';
let data = {};
let app = express()
.use('/data', expressJsonData({ data }));
var express = require('express');
var expressJsonData = require('@kjots/express-json-data').default;
var data = {};
var app = express()
.use('/data', expressJsonData({ data: data }));
Create an Express JSON Data router with the provided options.
Type: Object
Default: {}
The data object upon which the Express JSON Data router will operate.
Type: Number
or String
The maximum body size for PUT
, POST
and PATCH
requests.
The limit value is passed directly to bodyParser.json() without modification.
Type: String
or Array<String>
or Function<String, Boolean>
Default: [ 'application/json', 'application/json-patch+json' ]
The supported media types for PUT
, POST
and PATCH
requests.
The type value is passed directly to bodyParser.json() without modification.
All of the following HTTP methods may be used with the base URI (e.g. /data
) or with any path beneath the base URI
(e.g. /data/path/to/value
).
If the base URI is used, the HTTP request will operate on the entire data object.
If a path beneath the base URI is used, the request path will be treated as a JSON Pointer to a value within the data object, and the HTTP request will operate on that value only.
Return the current value of the data object or request path value.
Replace the contents of the data object or request path value with the request body.
This method will return the updated value of the data object or request path value.
Merge the request body into contents of the data object or request path value.
This method uses the _.merge
method from lodash to merge the
data, with the request body as the source object.
This method will return the updated value of the data object or request path value.
Apply the request body as a JSON Patch to the data object or request path value.
This method will accept either an Array
of JSON patch operations or an Object
containing a single JSON patch
operation.
This method will return the updated value of the data object or request path value.
Clear the contents of the data object, or remove the request path value from the data object.