Composable HTTP Client

2.1.7 · active · verified Tue Apr 21

request-compose is a lightweight, dependency-free HTTP client for Node.js, built around the paradigm of function composition. It empowers developers to construct highly customized HTTP request and response pipelines by chaining together small, single-purpose middleware functions. The library's core philosophy emphasizes zero external dependencies, minimal abstraction, and stateless operation, offering a flexible and performant foundation for various HTTP interaction patterns. Its current stable version is 2.1.7. While a specific release cadence is not explicitly defined, the package appears actively maintained given its npm version and GitHub activity. Key differentiators include its extreme modularity, functional programming approach, and a footprint that includes no external runtime dependencies, contrasting with more opinionated HTTP clients by providing granular control over every step of the request-response lifecycle without imposing a rigid structure.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `request-compose` by creating a composed HTTP client, setting default headers, fetching user data from GitHub, and parsing the JSON response. This example leverages the bundled Request and Response middlewares.

import compose from 'request-compose';

const Request = compose.Request;
const Response = compose.Response;

(async () => {
  try {
    const { res, body } = await compose(
      Request.defaults({headers: {'user-agent': 'request-compose'}}),
      Request.url('https://api.github.com/users/simov'),
      Request.send(),
      Response.buffer(),
      Response.string(),
      Response.parse()
    )();
    console.log(res.statusCode, res.statusMessage);
    console.log(res.headers['x-ratelimit-remaining']);
    console.log(body);
  }
  catch (err) {
    console.error(err);
  }
})();

view raw JSON →