http-status-helper

1.0.0 • Public • Published

Dependency Status NPM Version Downloads

http-status-helper

This package will help a send the necessary and correct status into Request's

  • How to use:
const StatusHelper = require('http-status-helper')();
const status = new StatusHelper();

Note: Into your Request, use getStatus() method (Default is return the code of status):

  router.get('/', (req, res, next) => {
    res.status(status.getStatus('OK')).send('Hello, World');
  });

To use another information retrieve getStatus() method, use:

  status.getStatus('OK', 'description'); // The request has succeeded
  status.getStatus('Forbidden', 'code'); // 403
  status.getStatus('Not Found', 'metadata'); // 'Not Found'
  • Method List:
    • getInfoStatusCode(required Code) (Return an Object with status information's):
        status.getInfoStatusCode(200); // { metadata: 'OK', description: 'The request has succeeded' }
    • getInfoStatusByName(required Name) (Return an Object with status information's):
      status.getInfoStatusByName('OK'); // { metadata: 'OK', description: 'The request has succeeded', indexOf: 4, code: 200 }
    • getAllStatusList() (Return an Array with all status code):
      status.getAllStatusList(); // [ '100', '101', '102', '103', '200', '201', '202', '203', ...]
    • getAllStatusWithDescription(likeArray = false) (Return an Object or Array with All status information's):
      status.getAllStatusWithDescription(true); // ['200', { metadata: 'OK', description: 'The request has succeeded' }, '201', ...]
      status.getAllStatusWithDescription(false); // { '508': { metadata: 'Loop Detected', description: 'The server detected an infinite loop while processing the request.'}, ...
    • getStatus(required statusName) (Return an specific information about status):
     status.getStatus('OK', 'description'); // The request has succeeded
     status.getStatus('Forbidden', 'code'); // 403
     status.getStatus('Not Found', 'metadata'); // 'Not Found'

Readme

Keywords

none

Package Sidebar

Install

npm i http-status-helper

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

18.1 kB

Total Files

5

Last publish

Collaborators

  • douglasbarbosafald