1.0.1 • Published 8 years ago

@dsninjas/response v1.0.1

Weekly downloads
1
License
ISC
Repository
bitbucket
Last release
8 years ago

ds-util-response

Response Helpers for node.js projects

This module makes it easy to format your response in node.js applications.

Installation

  • Make sure that Node.js installed.
  • Install Node.js library with npm:
npm install @dsninjas/response
  • You can also install Node.js library with yarn:
yarn add @dsninjas/response

Usage

constructor(Raven)

The constructor helps you configure the response helper class.

const responseHelper = new ResponseHelper(Raven);

The constructor takes the following options:

  1. constructor(Raven) (required): this is a refernce to the global Raven object.

json(status, res, message, data, meta)

This method helps you format your json response.

const responseHelper = new ResponseHelper(Raven);
const status = 200;
const message = 'Success';
const data = {};
responseHelper.json(status, res, message, data);
  1. status (required): this is the status of the response.
  2. res (required): this is the response object.
  3. message (required): this is the message of the response.
  4. data (optional): this is the data with the response.
  5. meta (optional): this is the meta data with the response.

error(err, res)

This method helps you to format your error.

const responseHelper = new ResponseHelper(Raven);
responseHelper.error(err, res);
  1. err (required): this is the error object.
  2. res (required): this is the response object.

customError(res, data)

This method helps you to generate the token.

const responseHelper = new ResponseHelper(Raven);
responseHelper.customError(res, data);
  1. res (required): this is the response object.
  2. data (optional): this is the data with the response.
1.0.1

8 years ago

1.0.0

8 years ago