Library to standardize api response for services.
import { OkResponse } from "roit-response-api-node"
app.post('/users', function(req, res) {
// Send to client
apires.send(OkResponse(user, 'User successfully created.'));
}
import { ErrorResponse } from "roit-response-api-node"
app.post('/users', function(req, res) {
const errors = [{
code: XXX,
message: "Error in execute request!"
}]
// Send to client
apires.send(ErrorResponse(errors, 'User successfully created.'));
}
SUCCESS
Content-Type: application/json
{
"status": "SUCCESS",
"message": "User successfully created.",
"data": { ... },
"errors": null
}
ERROR
Content-Type: application/json
{
"status": "ERROR",
"message": "Error in create user.",
"data": null,
"errors": [
{
"code": XXX,
"message": "Error in execute request!"
}
]
}