New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jsonder

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonder

Create a JSON API with reasonable looking responses

latest
Source
npmnpm
Version
0.0.7
Version published
Maintainers
1
Created
Source

Jsonder

Provides a simple interface for creating unified JSON API responses in Express.js apps.

Installation

You can install Jsonder using NPM:

npm install jsonder

Basic usage

import jsonder from 'jsonder'.

const api = jsonder();

Jsonder provides two basic methods for handling API responses: sendSuccess and sendFail. These methods take a response object res and either a resource to send or an error, respectively.

Successful response:

api.sendSuccess(res, { id: '123456', greeting: 'Hello, World!' });

Each resource must have an id field of type string.

You can also provid an array of resources to send.

api.sendSuccess(res, [
  { id: '123456', greeting: 'Hello, World!' },
  { id: '123457', greeting: 'Hi, World!' },
]);

Error Response:

Each error must have these fields:

  • status: a HTTP status of the error
  • code: a human readable code of the error as a string,
  • detail: a detailed human readable explanation of the error.
jsonder.sendFail(res, { 
  status: 400,
  code: 'invalid_body',
  detail: 'you forgot to provide a body'
});

You can provide an array of errors. Jsonder will choose the most general HTTP status code for the whole reqeust.

FAQs

Package last updated on 12 Apr 2023

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