{"id":15804,"library":"request-compose","title":"Composable HTTP Client","description":"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.","status":"active","version":"2.1.7","language":"javascript","source_language":"en","source_url":"https://github.com/simov/request-compose","tags":["javascript","functional","compose","composable","http","client","typescript"],"install":[{"cmd":"npm install request-compose","lang":"bash","label":"npm"},{"cmd":"yarn add request-compose","lang":"bash","label":"yarn"},{"cmd":"pnpm add request-compose","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The main composition function (`compose`) is the default export of the package.","wrong":"import { compose } from 'request-compose';","symbol":"compose","correct":"import compose from 'request-compose';"},{"note":"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.","wrong":"import { Request } from 'request-compose';","symbol":"Request","correct":"import compose from 'request-compose'; const { Request } = compose;"},{"note":"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.","wrong":"import { Response } from 'request-compose';","symbol":"Response","correct":"import compose from 'request-compose'; const { Response } = compose;"}],"quickstart":{"code":"import compose from 'request-compose';\n\nconst Request = compose.Request;\nconst Response = compose.Response;\n\n(async () => {\n  try {\n    const { res, body } = await compose(\n      Request.defaults({headers: {'user-agent': 'request-compose'}}),\n      Request.url('https://api.github.com/users/simov'),\n      Request.send(),\n      Response.buffer(),\n      Response.string(),\n      Response.parse()\n    )();\n    console.log(res.statusCode, res.statusMessage);\n    console.log(res.headers['x-ratelimit-remaining']);\n    console.log(body);\n  }\n  catch (err) {\n    console.error(err);\n  }\n})();","lang":"typescript","description":"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."},"warnings":[{"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;`.","message":"The `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`.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"`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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always wrap calls to your composed functions in `try...catch` blocks or chain a `.catch()` handler to the returned promise.","message":"Since `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Use `import compose from 'request-compose'; const { Request, Response } = compose;` (ESM) or `const compose = require('request-compose'); const { Request, Response } = compose;` (CommonJS).","cause":"Attempting to import `Request` or `Response` as named exports from 'request-compose' when they are properties of the default export.","error":"TypeError: (0 , _requestCompose.Request) is not a function"},{"fix":"Use `import compose from 'request-compose';` (ESM) or `const compose = require('request-compose');` (CommonJS).","cause":"Trying to import the `compose` function as a named export when it is the default export of the package.","error":"TypeError: compose is not a function"},{"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.","cause":"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.","error":"Error: connect ECONNREFUSED"},{"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.","cause":"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`.","error":"SyntaxError: Unexpected token 'export' (when using Node.js)"}],"ecosystem":"npm"}