1.0.1 • Published 8 years ago
@dsninjas/response v1.0.1
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:
- 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);
- status (required): this is the status of the response.
- res (required): this is the response object.
- message (required): this is the message of the response.
- data (optional): this is the data with the response.
- 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);
- err (required): this is the error object.
- 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);
- res (required): this is the response object.
- data (optional): this is the data with the response.