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
resHandlersuccess resdata # JSON Response # HTTP Status: 200 # {"status": "success", "data": <data object>}
created
resHandlercreated 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
resHandlerserverError errorres # JSON Response # HTTP Status: 500 # {"status": "error", "message": <error.message>}
validationError
resHandlervalidationError errorsres # JSON Response # HTTP Status: 400 # {"status": "fail", "message": "Validation Error", "data": <errors>}