The `r2` package is a minimalist, promise-based HTTP client library envisioned as a spiritual successor to the popular `request` package. It distinguishes itself by being built primarily upon the browser's Fetch API, with Node.js support provided through shims, resulting in a substantially smaller footprint, particularly for browser environments (e.g., 66KB uncompressed for `r2` versus 2MB for `request` when bundled). The library's API is designed for modern JavaScript development, leveraging `async/await` for asynchronous operations. The current stable version is 2.0.1, released in April 2018. Its release cadence has been effectively halted since then, indicating long-term dormancy. A primary differentiator is its Fetch API-first design, aiming for simplicity and efficiency over feature-rich complexity, making it a lightweight option for basic HTTP interactions.
npm install r2Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic GET requests for text, PUT requests with JSON payloads, and GET requests with custom headers using r2's async/await interface.
Consult the v2.0.0 source code or documentation (if available) to understand the new API surface, as explicit migration guides are scarce.
Evaluate alternatives like `node-fetch`, `axios`, or the native `fetch` API (with a polyfill for Node.js) for projects requiring active maintenance, security updates, and modern features. Use `r2` with caution in production, especially for new projects.
Use `const r2 = require("r2")` for Node.js environments. For browser environments where ES Modules are preferred, consider bundling with tools like Webpack or Rollup, or use a modern HTTP client with native ESM support.Wrap the code using `await` in an `async` function and call it. Example: `async function myFunc() { await r2(...); } myFunc();`.`r2` is a function that returns a promise-like object directly, not a class. Call it as `await r2('url').text`. Ensure `const r2 = require('r2')` is correctly defined and in scope.Verify the URL is correct and the target server is running and accessible from your environment. For 'localhost', ensure the server is listening on the correct port and address.
No dependency data recorded yet.