comeback v1.0.0
comeback-js
comeback-js is a simple node library for easily returning standardized response bodies and error codes to the client.
The goal of this library isn't to do anything revolutionary, but rather to just cut down on the code I have to write when sending content back to the client through an express API. It saves a line of code here and there, and just makes an express developer's life easier. I think.
API
comeback provides a collection of functions, each of which corresponds to an HTTP status code. In general, they take in an express-js response object and something which should be returned to the client.
200
The 200 level APIs really only exist to match the rest of the APIs in the library so you only have to use comeback if you want. They don't offer much functionality beyond that.
comeback.ok(res, object)
Sends the object back to the client with a 200 code.
comeback.created(res, object)
Sends the object back to the client with a 201 code.
comeback.accepted(res, object)
Sends the object back to the client with a 202 code.
400
All of the 400 level APIs take in a message. If this message is empty or null, a defualt message is sent. The returned object to the client will look like this:
{
"status": 400,
"message": "Bad Request"
}
comeback.badRequest(res, message)
Sends the message and a 400 back to the client. Default: Bad Request
comeback.unauthorized(res, message)
Sends the message and a 401 back to the client. Default: Unauthorized
comeback.forbidden(res, message)
Sends the message and a 403 back to the client. Default: Forbidden
comeback.notFound(res, message)
Sends the message and a 404 back to the client. Default: Resource Not Found
500
comeback.internal(res, message)
Sends the message and a 500 back to the client. Default: Internal Server Error
10 years ago