0.1.2 • Published 9 years ago

batch-call v0.1.2

Weekly downloads
9
License
-
Repository
github
Last release
9 years ago

Batch Call Wrapper

build status

This uses request inside and allows to wrap several calls into one batch.

Server-side example:

require('express').all('/batch', require('batch-call')).listen(3000);

Client-side call:

var request = require('request');
var payload = {
    users: {
        url: 'http://example.com/users/1',
    },
    project2: {
        url: 'http://example.com/projects/2',
        method: 'POST',
        headers: {
            Authentication: 'auth'
        },
        json: { name: "project2" }
    },
    simple: 'http://example.com/simle/get'
}
request({ url: 'http://0.0.0.0:3000/batch', json: payload }, function (err, res, body) {
    console.log(body);
};

Result of the call:

{
    users: {
        body: [ 'user1', 'user2' ],
        headers: {}
    },
    project2: {
        body: { id: 2, name: 'project2' }
        headers: {}
    },
    simple: {
        body: 'result',
        headers: {}
    }
}
0.1.2

9 years ago

0.1.1

9 years ago