Decorator for Hapi request object.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
README.md
index.js
package.json

README.md

hapi-request

Decorator for Hapi request object.

The idea is that handlers can be used as prerequsite methods as interchangeable, reusable pieces of code.


Install

npm install hapi-request

Usage

var hapiRequest = require('hapi-requst');

// Set up our handler/prerequsite

var someHandler = hapiRequest(function (request) {
    
    var someObj = {};
    
    // Do some crazy go nuts stuff here ...
    
    // When we reply with this function, hapi-request detects
    // if this is a Hapi prerequsite or a Hapi handler
    
    request.reply(someObj);
});

//

server.route({
    method: 'GET',
    path: '/some-route',
    handler: someHandler // <~~ Can be used as Hapi handler
});

// 

server.route({
    method: 'GET',
    path: '/some-OTHER-route',
    pre: {
        foo: someHandler // <~~ Can be used as a Hapi prerequsite
    }
    handler: function (request) {
        var foo = request.pre.foo;
        request.reply(foo);
    }
});