Registry / http-networking / request-promise-middleware-framework

request-promise-middleware-framework

JSON →
library3.0.6jsnpmunverified

This package provides a framework for intercepting and modifying HTTP requests and responses made using the `request-promise` HTTP client. It enables developers to define middleware functions that can execute custom logic before an HTTP call, modify request options, or process responses. The current stable version is 3.0.6. The release cadence appears to be irregular, driven primarily by dependency updates and security fixes rather than new feature additions. A key differentiator is its explicit handling of `resolveWithFullResponse`, defaulting it to `true` within the middleware pipeline to ensure full response access for all middleware components, diverging slightly from `request-promise`'s default. This framework is specifically designed for `request-promise` and does not support other HTTP clients, serving as a dedicated extensibility layer for that ecosystem.

npm install request-promise-middleware-framework
INSTALL
IMPORT
SIG · REQUEST-PROMISE-MI
R
request-promise-middleware-framework
http-networkingjavascriptv3.0.6
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

RequestPromiseMiddlewareFramework
import RequestPromiseMiddlewareFramework from 'request-promise-middleware-framework';
const RequestPromiseMiddlewareFramework = require('request-promise-middleware-framework');
While examples show `require()`, the `package.json` specifies `type: commonjs` but also a `main` entry that could be consumed by bundlers. For modern Node.js and TypeScript, an ES module import is preferred if transpiled or configured correctly. The package's ES6 syntax in v2.0.0 suggests it's designed for modern JS environments.
RequestPromiseMiddlewareFramework (CJS)
const RequestPromiseMiddlewareFramework = require('request-promise-middleware-framework');
This is the common CommonJS import style shown in the documentation and examples.

This quickstart demonstrates how to define and register two types of middleware: one for logging request/response details and another for completely short-circuiting an HTTP call based on the URL. It then shows how to obtain and use the middleware-enabled `request-promise` instance.

import RequestPromiseMiddlewareFramework from 'request-promise-middleware-framework'; import rpBase from 'request-promise'; // Define a simple logging middleware function loggingMiddleware(options, callback, next) { console.log(`[Middleware] Requesting: ${options.uri || options.url}`); const _callback = (err, response, body) => { if (err) { console.error(`[Middleware] Error for ${options.uri || options.url}:`, err.message); } else { console.log(`[Middleware] Received response for ${options.uri || options.url} with status: ${response ? response.statusCode : 'N/A'}`); } callback(err, response, body); }; next(options, _callback); } // Define a short-circuiting middleware example function shortCircuitMiddleware(options, callback, next) { if (options.uri === 'http://example.com/short-circuit') { console.log('[Middleware] Short-circuiting request to http://example.com/short-circuit'); const mockBody = { message: 'Short-circuited by middleware' }; const mockResponse = { statusCode: 200, body: mockBody, headers: { 'content-type': 'application/json' } }; callback(null, mockResponse, mockBody); } else { next(options, callback); } } // Initialize the framework with request-promise and our middleware const rpMiddlewareFramework = new RequestPromiseMiddlewareFramework( { rp: rpBase }, [loggingMiddleware, shortCircuitMiddleware] ); // Get the middleware-enabled request-promise instance const rp = rpMiddlewareFramework.getMiddlewareEnabledRequestPromise(); // Use the new rp instance async function makeRequests() { try { // Request that goes through the network const result1 = await rp('http://httpbin.org/get'); console.log('Result 1 (full response body snippet):', result1.slice(0, 100), '...'); // Request that is short-circuited const result2 = await rp('http://example.com/short-circuit'); console.log('Result 2 (short-circuited):', result2); } catch (error) { console.error('An error occurred:', error.message); } } makeRequests();
Debug
Known issues
breakingVersion 3.0.0 removed the dependency on `bluebird` and now utilizes native Promises by default. If your application relied on `bluebird`'s specific features or custom Promise extensions, you might need to adjust your code or explicitly provide `bluebird` to the framework initialization.
fix
If you need `bluebird`, pass it during initialization: `new RequestPromiseMiddlewareFramework({ rp: require("request-promise"), PromiseDependency: require("bluebird") }, middleware);`. Otherwise, ensure your code is compatible with native Promises.
affects: >=3.0.0
breakingVersion 1.0.0 changed the default behavior for `resolveWithFullResponse` to `true`. While `request-promise` typically defaults this to `false`, this framework forces it to `true` internally for middleware consistency. If your code explicitly expected `resolveWithFullResponse: false` by default and was not setting it, this change would affect the shape of the returned value.
fix
Ensure your request options explicitly set `resolveWithFullResponse: false` if you absolutely require the raw body instead of the full response object, or update your code to handle the full response object.
affects: >=1.0.0
gotchaThe framework's default for `resolveWithFullResponse` is `true` within the middleware pipeline, overriding `request-promise`'s default. While you can set `resolveWithFullResponse: false` on an individual `rp` invocation, the middleware pipeline itself will internally always operate with the full response object for consistency, potentially leading to unexpected behavior if middleware expects only the body.
fix
Middleware functions should always be prepared to receive a full response object (`response` and `body` parameters) regardless of the `resolveWithFullResponse` setting on the `rp` call. If you need to return only the body to the consumer, you must extract it explicitly in your final middleware or after the `rp` call.
affects: >=1.0.0
breakingSecurity vulnerabilities are periodically patched (e.g., in v3.0.6, v3.0.5, v3.0.3) often related to underlying dependencies like `eslint-utils` or other core packages. Failing to update to the latest patch versions can expose applications to known CVEs.
fix
Regularly update the package to the latest patch version (e.g., `npm install request-promise-middleware-framework@latest`) to incorporate security fixes and dependency updates.
affects: <3.0.6
Errors
Common errors & fixes
TypeError: rpMiddlewareFramework.getMiddlewareEnabledRequestPromise is not a function
The `RequestPromiseMiddlewareFramework` constructor or instance was not correctly created or imported, or you're calling the method on a variable that isn't the framework instance.
fix
Ensure you correctly `require` or `import` the `RequestPromiseMiddlewareFramework` and instantiate it with `new RequestPromiseMiddlewareFramework(...)` before calling `getMiddlewareEnabledRequestPromise()`.
Error: Cannot find module 'request-promise'
The `request-promise` package is a required peer/runtime dependency that must be installed separately.
fix
Install `request-promise` using npm: `npm install request-promise`.
UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: X): Error: ...
A promise returned by `request-promise-middleware-framework` (or `request-promise`) was rejected, but the rejection was not caught by a `.catch()` block or `try...catch` in an `async` function.
fix
Always add a `.catch()` block to your promise chains (e.g., `rp(...).then(...).catch(err => console.error(err))`) or use `try...catch` with `await` in `async` functions to handle potential errors.
Upgrade
Version history
3.0.6latest on npm
Audit
Dependencies
request-promiserequiredThis is the core HTTP client that the middleware framework intercepts.
bluebirdoptionalOptional dependency for using an alternate Promise library instead of native Promises.
Agent activity
2 hits · last 30 days
node
2
Resources
request-promise-middleware-framework — npm install request-promise-middleware-framework · libregistry