express-bunch-middleware

1.0.4 • Public • Published

express-bunch-middleware

Express middleware to combine multiple API requests into one.

Build Status Coverage Status

Usage

const express = require('express');
const bunch = require('express-bunch-middleware');
const app = express();
 
app.use('/resources', bunch);
 
app.get('/api/users', (req, res) => {
    res.json([{name: 'John', surname: 'Doe'}]);
});
 
app.get('/api/countries/:id', (req, res) => {
    setTimeout(() => {
        res.json({name: 'United States of America', countryCode: 'USA'});
    }, 30)
});
 
app.listen(3000);

Description

API call like:

GET /resources?users=/api/users&country=/api/countries/23

will responds with:

{
    "users": [{
        "name": "John",
        "surname": "Doe"
    }],
    "countries": [{
        "name": "United States of America",
        "countryCode": "USA"
    }]
}

License

MIT

Package Sidebar

Install

npm i express-bunch-middleware

Weekly Downloads

4

Version

1.0.4

License

MIT

Last publish

Collaborators

  • oleksii.kukuruza