res-handler
v0.0.3
Published
Smart JSON API response handler.
Downloads
165
Readme
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 res, data
# JSON Response
# HTTP Status: 200
# {"status": "success", "data": <data object>}
created
resHandler.created res, data
# 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 error, res
# JSON Response
# HTTP Status: 500
# {"status": "error", "message": <error.message>}
validationError
resHandler.validationError errors, res
# JSON Response
# HTTP Status: 400
# {"status": "fail", "message": "Validation Error", "data": <errors>}