{"library":"r2","title":"r2 HTTP Client","description":"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.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install r2"],"cli":null},"imports":["const r2 = require('r2')","const r2 = require('r2'); await r2.get('https://example.com').text","await r2('https://example.com').text"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const r2 = require('r2');\n\nasync function fetchData() {\n  try {\n    // Fetch HTML content from Google\n    const html = await r2('https://www.google.com').text;\n    console.log('Google HTML (truncated):', html.substring(0, 100) + '...');\n\n    // Send a PUT request with JSON data and receive JSON response\n    const payload = { status: 'success', timestamp: Date.now() };\n    const jsonResponse = await r2.put('https://httpbin.org/put', { json: payload }).json;\n    console.log('HTTPBin PUT response:', jsonResponse);\n\n    // Fetch with custom headers\n    const headers = { 'x-custom-header': 'r2-test' };\n    const responseWithHeaders = await r2('https://httpbin.org/headers', { headers }).json;\n    console.log('HTTPBin Headers response:', responseWithHeaders.headers['X-Custom-Header']);\n\n  } catch (error) {\n    console.error('Error fetching data:', error);\n  }\n}\n\nfetchData();","lang":"javascript","description":"Demonstrates basic GET requests for text, PUT requests with JSON payloads, and GET requests with custom headers using r2's async/await interface.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}