{"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,"search_vec":"'2.1.7':75 'abstract':55 'activ':88,96 'appear':87 'approach':105 'around':18 'built':17 'cadenc':80 'chain':37 'client':3,14,120,144 'compos':1,6,141,142 'composit':23 'construct':28 'contrast':115 'control':124 'core':48 'current':71 'custom':30 'defin':84 'depend':11,53,114 'dependency-fre':10 'develop':26 'differenti':98 'emphas':50 'empow':25 'everi':126 'explicit':83 'extern':52,112 'extrem':101 'flexibl':61 'footprint':108 'foundat':64 'free':12 'function':22,44,103,140 'github':95 'given':90 'granular':123 'high':29 'http':2,13,31,67,119,143 'impos':135 'includ':99,110 'interact':68 'javascript':139 'key':97 'librari':46 'lifecycl':133 'lightweight':9 'maintain':89 'middlewar':43 'minim':54 'modular':102 'node.js':16 'npm':92 'offer':59 'oper':58 'opinion':118 'packag':86 'paradigm':20 'pattern':69 'perform':63 'philosophi':49 'pipelin':35 'program':104 'provid':122 'purpos':42 'releas':79 'request':5,32,131 'request-compos':4 'request-respons':130 'respons':34,132 'rigid':137 'runtim':113 'singl':41 'single-purpos':40 'small':39 'specif':78 'stabl':72 'stateless':57 'step':127 'structur':138 'togeth':38 'typescript':145 'various':66 'version':73,93 'without':134 'zero':51","created_at":"2026-04-21T18:00:06.546806+00:00","updated_at":"2026-04-21T18:00:06.546806+00:00","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","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/simov/request-compose","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/request-compose","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-20","install_tag":null}}