xhr-request is an extremely compact HTTP/HTTPS client designed for both Node.js and browser environments, currently at version 1.1.0. Its primary differentiator, especially at the time of its last update over seven years ago, was its minimal bundle size, achieving significantly smaller outputs compared to contemporaries like `request` or `got` by intelligently leveraging `xhr` in the browser and `simple-get` in Node.js. It supports JSON, ArrayBuffer, and text response types and offers basic options for method, headers, query parameters, and a request body. The project has not received updates in many years, implying an abandoned status with no active release cadence, making it suitable mainly for legacy applications or highly constrained environments where bundle size is paramount and modern features or security updates are not a concern.
npm install xhr-requestVerified import paths — ran on the pinned version, not inferred.
Demonstrates fetching JSON data and sending a PUT request with JSON body and query parameters using the callback-based API.
Migrate to actively maintained alternatives like `axios`, `node-fetch` (Node.js), or the built-in `fetch` API (browser).
Wrap calls in a Promise: `new Promise((resolve, reject) => request(url, opts, (err, data) => err ? reject(err) : resolve(data)))`.
Use `const request = require('xhr-request')` in CommonJS modules, or configure your bundler (e.g., Webpack, Rollup) to handle CJS imports in ESM projects. Alternatively, use a dynamic import: `import('xhr-request').then(module => module.default(...))`.Create a `declarations.d.ts` file with `declare module 'xhr-request' { function request(url: string, opts?: any, cb?: Function): any; export = request; }` or install `@types/xhr-request` if one becomes available (unlikely given its status).Ensure your file is treated as CommonJS, or use a bundler (like Webpack/Rollup) to handle the CJS module in an ESM context. For direct browser use, ensure it's loaded as a script and available globally or wrapped by a bundler.
Verify the import syntax. For CommonJS, use `const request = require('xhr-request')`. If using a bundler in an ESM project, it might be `import request from 'xhr-request'` if the bundler handles CJS default exports, or `import * as request from 'xhr-request'` then `request.default(...)`.For development, set `NODE_TLS_REJECT_UNAUTHORIZED='0'` (use with extreme caution in production). Ensure your system's root certificates are up-to-date, or provide custom CA certificates if connecting to internal services.