0.0.3 • Published 12 years ago
res-handler v0.0.3
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>}