Express Request Proxy

2.2.2 · abandoned · verified Wed Apr 22

express-request-proxy is an Express.js middleware designed for creating high-performance streaming HTTP reverse proxies. It enables features like transparent caching via Redis, server-side injection of sensitive API keys and headers, custom route parameter handling, and response transformations. The package is built upon the widely used, but now deprecated, `request` HTTP client library. Its last major release was 2.x, with version 2.2.2 being the latest. Given its dependency on the unmaintained `request` library and lack of recent updates (last commit August 2018), the package is effectively abandoned, limiting its viability for new projects and posing potential maintenance and security risks.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates setting up an Express server to use `express-request-proxy` to forward requests to a public API, including server-side injection of API keys and custom headers, and utilizing Redis for caching responses.

const express = require('express');
const redis = require('redis');
const requestProxy = require('express-request-proxy');
require('redis-streams')(redis); // Extend redis client with streams functionality

const app = express();
const port = 3000;

// Create a Redis client for caching
const redisClient = redis.createClient();
redisClient.on('error', (err) => console.error('Redis Client Error', err));

// Connect to Redis (async operation)
async function connectRedis() {
  await redisClient.connect();
  console.log('Connected to Redis');
}
connectRedis();

app.get(
  '/api/:resource/:id',
  requestProxy({
    cache: redisClient, // Use the connected Redis client
    cacheMaxAge: 60, // Cache for 60 seconds
    url: 'https://jsonplaceholder.typicode.com/:resource/:id', // Example public API
    query: {
      api_key: process.env.SOMEAPI_SECRET_KEY ?? 'demo-key' // Inject sensitive key from env
    },
    headers: {
      'X-Custom-Auth': process.env.SOMEAPI_CUSTOM_HEADER ?? 'secret-value' // Inject custom header
    }
  })
);

app.get('/', (req, res) => {
    res.send('Proxy server running. Try /api/posts/1 or /api/users/2');
});

app.listen(port, () => {
  console.log(`Proxy server listening at http://localhost:${port}`);
  console.log('Test with: curl http://localhost:3000/api/posts/1');
});

view raw JSON →