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-frameworkVerified import paths — ran on the pinned version, not inferred.
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.
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.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.
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.
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.
Ensure you correctly `require` or `import` the `RequestPromiseMiddlewareFramework` and instantiate it with `new RequestPromiseMiddlewareFramework(...)` before calling `getMiddlewareEnabledRequestPromise()`.
Install `request-promise` using npm: `npm install request-promise`.
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.