Socket
Socket
Sign inDemoInstall

@kjots/express-json-data

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kjots/express-json-data

Express JSON data router


Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

express-json-data

npm version

A JSON data object Express router with PATCH support.

Installation

npm install --save @kjots/express-json-data

Usage

As an ES6 module

import express from 'express';
import expressJsonData from '@kjots/express-json-data';

let data = {};

let app = express()
    .use('/data', expressJsonData({ data }));

As an ES5 module

var express = require('express');
var expressJsonData = require('@kjots/express-json-data').default;

var data = {};

var app = express()
    .use('/data', expressJsonData({ data: data }));

API

expressJsonData(options)

Create an Express JSON Data router with the provided options.

Options
data

Type: Object

Default: {}

The data object upon which the Express JSON Data router will operate.

limit

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

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.

HTTP Methods

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.

GET

Return the current value of the data object or request path value.

PUT

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.

POST

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.

PATCH

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.

DELETE

Clear the contents of the data object, or remove the request path value from the data object.

Keywords

FAQs

Package last updated on 10 Nov 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc