Skip to content

codastic/express-batch-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-batch-proxy

Batch API controller for ExpressJS.

Requires ExpressJS v4 and body parser.

Usage

var PORT = 8080;
var HOST = 'example.com'; // optional (default: 127.0.0.1)

var express = require('express'),
    bodyParser = require('body-parser'),
    batchProxy = require('express-batch-proxy');

var app = express();

app.use(bodyParser.json());

/* ... register other controllers ... */

app.post('/batch', batchProxy(PORT, HOST));

app.listen(8080);

Example Request

JSON Request body:

{"batch": [
    {"path": "/user/1234", "method": "GET", "headers": {"User-Agent": "foobar"}},
    {"path": "/user/1234/friends", "method": "GET"}]
}

Example Response

[{
    "request": {"path": "/user/1234", "method": "GET", "headers": {"User-Agent": "foobar"}},
    "response": {
        "headers": {
            "content-type": "application/json",
            "content-length": 1234
        },
        "body": {
            "id": 1234,
            "first_name": "John",
            "last_name": "Doe",
            "email": "[email protected]"
        },
        "statusCode": 200
    }
}, {
    "request": {"path": "/user/1234/friends", "method": "GET", "headers": {}},
    "response": {
        "headers": {
            "content-type": "application/json",
            "content-length": 1234
        },
        "body": {
            data: [
                1235,
                1236,
                1237,
                1238
            ]
        },
        "statusCode": 200
    }
}]

About

Batch API controller for ExpressJS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published