1.2.0 • Published 4 years ago
@studiowebux/response v1.2.0
Webux Response
This module allows to add new responses to express to provide custom responses.
Installation
Linux
npm i --save @studiowebux/response
Windows
npm i --save @studiowebux/response
Mac OS
npm i --save @studiowebux/response
Usage
Requirements
- Knowledge about the HTTP status code
Configurations
Each method have arguments,
these arguments are described below,
Functions
Responses available:
Success (HTTP 200)
body is Mandatory
res.success(body, msg, devMsg);
Created (HTTP 201)
body is Mandatory
res.created(body, msg, devMsg);
Updated (HTTP 200)
body is Mandatory
res.updated(body, msg, devMsg);
Deleted (HTTP 204)
id is Mandatory
res.deleted(id, msg, devMsg);
Forbidden (HTTP 403)
res.forbidden(msg, devMsg);
Bad Request (HTTP 400)
res.badRequest(msg, devMsg);
Server Error (HTTP 500)
res.serverError(msg, devMsg);
Not Found (HTTP 404)
res.notFound(msg, devMsg);
Unauthorized (HTTP 401)
res.unauthorized(msg, devMsg);
Unprocessable (HTTP 422)
res.unprocessable(msg, devMsg);
Custom
code and object are Mandatory
res.custom(code, object);
Example
Check the /examples directory.
Test
Tested with jest 24.9.0
Install jest globally
npm install -g jest
Launch the test
npm install
npm run test
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
SEE LICENSE IN license.txt