respond-with

1.1.1 • Public • Published

respond-with

Install

npm i --save respond-with

Usage

var respondWith = require('respond-with');
 
module.exports = function(app) {
  app.post('/myendpoint', function(req, res) {
    respondWith(
      req,
      res,
      doSomethingThatReturnsAPromise()
    );
  });
};

Configuration

respondWith.configure(function(config){
  config.responders.shift(
    {
      status: 'resolved',
      name: '404OnVoidGet',
      when: function(req, object){
        return req.method === 'GET' && (object === null || object === undefined)
      },
      respond: function(req, res){
        return res.status(404).json();
      }
    }
  );
});

Package Sidebar

Install

npm i respond-with

Weekly Downloads

0

Version

1.1.1

License

MIT

Last publish

Collaborators

  • mcasimir