Registry / http-networking / request-compose

request-compose

JSON →
library2.1.7jsnpmunverified

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.

npm install request-compose
INSTALL
IMPORT
SIG · REQUEST-COMPOSE
R
request-compose
http-networkingjavascriptv2.1.7
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compose
✓ import compose from 'request-compose';
✗ import { compose } from 'request-compose';
The main composition function (`compose`) is the default export of the package.
Request
✓ import compose from 'request-compose'; const { Request } = compose;
✗ import { Request } from 'request-compose';
The `Request` middleware factories (and `Response`) are properties of the default `compose` export, not named exports themselves. This pattern applies to both ESM and CommonJS usage.
Response
✓ import compose from 'request-compose'; const { Response } = compose;
✗ import { Response } from 'request-compose';
The `Response` middleware factories (and `Request`) are properties of the default `compose` export, not named exports themselves. This pattern applies to both ESM and CommonJS usage.

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); } })();
Debug
Known issues
gotchaThe `Request` and `Response` middleware factories are properties of the default `compose` export, not named exports. Attempting to destructure them directly from the module like `import { Request } from 'request-compose'` will result in `undefined`.
fix
For ESM, use `import compose from 'request-compose'; const { Request, Response } = compose;`. For CommonJS, use `const compose = require('request-compose'); const { Request, Response } = compose;`.
affects: >=1.0.0
gotcha`request-compose` offers a composition mechanism and basic middlewares, but it does not bundle a full HTTP client implementation by default. For protocols like HTTPS, you often need to supply your own initial request function that wraps Node.js's native `http` or `https` modules within your composition pipeline.
fix
Consult the 'Compose' section in the documentation for advanced examples illustrating how to integrate native `http`/`https` request logic into your custom composed client.
affects: >=1.0.0
gotchaSince `request-compose` operations are promise-based, robust error handling with `try...catch` blocks or `.catch()` handlers is critical. Neglecting to handle rejected promises can lead to unhandled promise rejections, potentially crashing Node.js processes in environments prior to Node.js 15 or causing silent failures.
fix
Always wrap calls to your composed functions in `try...catch` blocks or chain a `.catch()` handler to the returned promise.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , _requestCompose.Request) is not a function
Attempting to import `Request` or `Response` as named exports from 'request-compose' when they are properties of the default export.
fix
Use `import compose from 'request-compose'; const { Request, Response } = compose;` (ESM) or `const compose = require('request-compose'); const { Request, Response } = compose;` (CommonJS).
TypeError: compose is not a function
Trying to import the `compose` function as a named export when it is the default export of the package.
fix
Use `import compose from 'request-compose';` (ESM) or `const compose = require('request-compose');` (CommonJS).
Error: connect ECONNREFUSED
The underlying HTTP request failed, typically due to an incorrect URL, an unreachable host, or a server that is not running or not listening on the specified port.
fix
Verify the URL, hostname, and port provided to `Request.url()` or within your custom request options. Ensure the target server is operational and network access is permitted.
SyntaxError: Unexpected token 'export' (when using Node.js)
Attempting to use ESM `import`/`export` syntax in a Node.js environment configured for CommonJS, or in an older Node.js version without explicitly declaring `"type": "module"` in `package.json`.
fix
For CommonJS environments, use `require()` syntax (e.g., `const compose = require('request-compose');`). For ESM in Node.js, ensure your `package.json` contains `"type": "module"` and use `import` statements.
Upgrade
Version history
2.1.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
request-compose — npm install request-compose · libregistry