Skip to content

bifrost/express-request-bundler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express Request Bundler Build Status

Express middleware for bundling requests.

Install

$ npm install express-request-bundler --save

Usage

Imagine you have a REST based API and a SPA that need to access a lot of different endpoints when rendering a page. You would probably want to bundle up some of these requests in order to reduce overall overhead and latency.

Request:

http://localhost:8080/api/bundle?user1=api/users/1&user2=api/users/2

Response:

{
  "user1": {
    "statusCode": 200,
    "headers": {
      "x-powered-by": "Express",
      "content-type": "application/json; charset=utf-8",
      "content-length": "26",
      "etag": "W/\"1a-56b04a0c\"",
      "date": "Wed, 25 Feb 2015 18:02:21 GMT",
      "connection": "keep-alive"
    },
    "body": {
      "id": 1,
      "username": "dave"
    }
  },
  "user2": {
    "statusCode": 200,
    "headers": {
      "x-powered-by": "Express",
      "content-type": "application/json; charset=utf-8",
      "content-length": "29",
      "etag": "W/\"1d-d580b515\"",
      "date": "Wed, 25 Feb 2015 18:02:21 GMT",
      "connection": "keep-alive"
    },
    "body": {
      "id": 2,
      "username": "jessica"
    }
  },
  "errors": false
}

The middleware plugs directly in to your existing Express app. You just need to require the module.

var erb = require("express-request-bundler");

And add a bundle endpoint to your app.

app.get('/api/bundle', erb());

And you are done.

Licence

The MIT License (MIT)

About

Express middleware for bundling requests

Resources

Stars

Watchers

Forks

Packages

No packages published