res-handler

0.0.3 • Public • Published

resHandler

Simple and pretty JSON API responses in your express controllers.

resHandler = require 'res-handler'

Success Responses

All success responses are passed res and data. Where res is the express response object and data is the data you want to pass in the JSON response.

success

resHandler.success resdata 
 
# JSON Response 
# HTTP Status: 200 
# {"status": "success", "data": <data object>} 

created

resHandler.created resdata
 
# JSON Response 
# HTTP Status: 201 
# {"status": "success", "data": <data object>} 

Error Responses

All error responses are passed error / errors and res. Where error / errors is the error. In the case of validation errors you pass in the validation errors.

serverError

resHandler.serverError errorres
 
# JSON Response 
# HTTP Status: 500 
# {"status": "error", "message": <error.message>} 

validationError

resHandler.validationError errorsres
 
# JSON Response 
# HTTP Status: 400 
# {"status": "fail", "message": "Validation Error", "data": <errors>} 

Package Sidebar

Install

npm i res-handler

Weekly Downloads

9

Version

0.0.3

License

MIT

Last publish

Collaborators

  • samora