procnet

1.2.6 • Public • Published

Procnet build

A remote provider built for use with pogostick (although you could use a different rpc library).

Define Services

Seperate network code from your service definition.

// For example a `math` service
module.exports = procnet.service(function() {
    return {
        add: function(a, b) {
            return a + b;
        },
        multiply: function(a, b) {
            return a * b;
        }
    }
});

Compose Services

// An example `rectangle` service.
module.exports = procnet.service(['math'], function(math) {
    return {
        surface: function(h, w) {
            return math.multiply(h, w);
        }
    };
});

Unit Test Services

One of the benefit of seperating your logic this way is the way it permits you to unit test your services, mocking dependencies.

// You can pick any promise library you want, just need to provide a factory function.
var mock = procnet.mocker(promiseFactory);
var mocked = mock({ 
    math: {
        // Our fake multiply always returns 1 instead
        multiply: function() { return 1; }
    } 
}, rectangle);
 
mocked
    .surface(2, 2)
    .then(function(r) {
        assert.equal(r, 1);
    });

Read More

/procnet/

    Package Sidebar

    Install

    npm i procnet

    Weekly Downloads

    5

    Version

    1.2.6

    License

    MIT

    Last publish

    Collaborators

    • aghost7