apis-resource

Add resource helper for node apis lib

npm install apis-resource
18 downloads in the last week
28 downloads in the last month

apis-resource

Add resource helper for apis lib

Resource

res.name = 'user',
res.get = function(auth, data, cb) {};
res.create = function(auth, data, cb) {};

request or response

request = {
    get: function(options) {
        return {email: email}
    },

    create: function(options) {
        return {
            email: email,
            password: str,
            name: opt(str),
        }
    }
}

Usage

add(
    contract,       //contract handler 
    {
        handler     //auth handler
        authFunc    //auth function
    },           
    {
        base,       //api base path, ex. '/api'
        api,        //resource api unit
        request,    //request validators
        response,   //optional, response validators
        options     //any options for validators
    }
)

Example

var addResource = require('apis-resource').add;
...

Contract.prototype.unitInit = function (units) {
    var auth =  units.require('auth').handler;
    var userApi =  units.require('user.api');
    var userRequest =  units.require('user.request');

    add(this, {handler: auth}, {
        base: '/api/1', 
        api: userApi, 
        request: userRequest
    });
};
npm loves you