npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

buff-express

v0.5.4

Published

An API gateway inspired by Netflix Zuul

Downloads

4

Readme

Build Status

An express API gateway inspired by netflix zuul.

What is Bruff

Bruff is an API Gateway built as an express middleware on Nodejs. It has the ability to route requests to multiple upstream servers or endpoints asynchronously or synchronously if dependency exist.

Why did we built Bruff

Our client applications (Web and Mobile) consume resources from different micro-services in order to perform different operations. The mobile client particularly had performance issues due to the fact that it called multiple endpoints from different services to perform a user action and or got response data more than it needed which increased latency. To solve this problem we found ourselves building middleware called Backend For Frontend (BFF) which will do all the work of calling multiple services, aggregating their responses and trimming out unneeded fields in the response for the client app. This approach increased the mobile client performance greatly.

For example, when a user to logs in into our mobile app the app needs to get access token from a service, and then calls another service to get the profile data of the user. The BFF came in to provide the mobile client with one new endpoint called /login that abstracts this sequence of actions from the mobile app.

Because we realized we will be building a lot of middleware applications like this, we decided to embark on the journey of looking for a framework for this and we found Netflix Zuul. The problem is we could not use Netflix zuul as our engineering team could not support development in Java then we built our in house tool and called it Bruff.

What can Bruff do for you?

  • Dynamic routing - Bruff can route single request, multiple dependent and multiple independent requests to different upstream servers
  • With it, you can filter and mutate responses from upstream servers to specific responses needed by client applications.
  • You can enable caching in Bruff express (under development).
  • You can do load balancing in bruff.
  • Others - because Bruff in itself is an express middleware you can do other things such as authentication with other express middlewares. You only need to call your middleware before calling bruff.

Getting started

To get started with Bruff you need to install the bruff npm module

npm install bruff-express --save

Create a bruff configuration module which holds the information and instruction you have for bruff e.g gateway.js

module.exports = {
    gateway: [
        {
            base: "POST:/login", //the client will request for the endpoint
            _to: [{ //bruff will make request to these two endpoints for you
                url: "localhost:8987/oauth/token",
                title: "oauth",
                method: "POST",
                requires: {
                    form: {
                        username: "{{client.req.body.username}}", //bruff knows to use username from the client request
                        password: "{{client.req.body.password}}",
                        client_id: context => context.client.req.body.clientId,
                        client_secret: context => context.client.req.body.clientSecret
                    }
                }
            }, {
                url: ["localhost:8787/me", "localhost:8787/me"], //will select only one
                title: "me",
                cacheKey: "{{responses.0.access_token}}", //bruff knows to cache the response of this endpoint with access token from the response of the endpoint above
                method: "GET",
                requires: {
                    headers: {
                        Authorization: "Bearer {{responses.0.access_token}}" //bruff knows to send the request with header set to access token from response of the request above
                    }
                },
                after: [] //functions to run when response return from upstream server
            }],
            order: "sync" //tells bruff that the _to endpoints need to happen one after the other because the last one neeeds the response from the first one
        }
    ],
    config: {
        cache: {
            time: 3600, //number of seconds to cache
            get: function () {},
            set: function () {}
        }
    }
}

Once you have your configuration set you can then go to your app.js and do :

var bruff = require('bruff-express');
var bruffConfig = require('./gateway);
var express = require('express);

var app = express();

app.use(bruff(bruffConfig));

app.list(8989);