response-api
v1.0.2
Published
Library for standardizing the API responses
Downloads
2
Readme
response-api
Library for standardizing the API responses.
Installation
npm install scapegoat --save
Usage
The library has multiple methods for different types of response
- success(message, object, session)
- message: A description for the response that can be displayed on the client
- object: Data that will be sent to the client (ex. User list, Porfile and so on)
- session: Parameter that is checked to see if the user has an active session
responseApi.success('User successfully created', {
fistName: "John",
lastName: "Doe",
email: "[email protected]"
}, req.user);
{
timestamp: "1447331318",
hasSession: true,
error: null,
success: {
message: "User successfully created",
object: {
fistName: "John",
lastName: "Doe",
email: "[email protected]"
}
}
}
- error(message, code, session)
- message: A description for the response that can be displayed on the client
- code: Error code that is returned to the client to enhance the possiblity of customizing the client app error response
- session: Parameter that is checked to see if the user has an active session
responseApi.error('Sorry, our server has failed us', 500, req.user);
{
timestamp: "1447331318",
hasSession: true,
error: {
message: "Sorry, our server has failed us",
code: 500
},
success: null
}