http-status-helper
This package will help a send the necessary and correct status into Request's
Last updated 10 months ago by douglasbarbosafald .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install http-status-helper 
SYNC missed versions from official npm registry.

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'
    

Current Tags

  • 1.0.0                                ...           latest (10 months ago)

1 Versions

  • 1.0.0                                ...           10 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |