Registry / http-networking / xhr-request

xhr-request

JSON →
library1.1.0jsnpmunverified

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-request
INSTALL
IMPORT
SIG · XHR-REQUEST
X
xhr-request
http-networkingjavascriptv1.1.0
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.

request
const request = require('xhr-request')
import request from 'xhr-request'
xhr-request is a CommonJS module. Direct ESM import will fail without a bundler or dynamic import.
RequestCallback
/** @param {function(Error|null, any, object)} callback */
As a JavaScript-only library without TypeScript types, callbacks are typically documented with JSDoc.

Demonstrates fetching JSON data and sending a PUT request with JSON body and query parameters using the callback-based API.

const request = require('xhr-request') // Example: Loading JSON data from an API request('https://api.github.com/users/octocat', { json: true }, function (err, data) { if (err) { console.error('Error fetching user data:', err); return; } console.log('GitHub User (Octocat):', data.login); console.log('Followers:', data.followers); }); // Example: Sending a PUT request with a JSON body and query parameters // Note: This URL will likely fail with a 404/405 as it's a dummy endpoint. request('https://httpbin.org/put', { method: 'PUT', json: true, body: { status: 'active', user: 'testuser' }, query: { id: '123', region: 'us-east' }, headers: { 'X-Custom-Header': 'my-value' } }, function (err, data, response) { if (err) { console.error('Error in PUT request:', err); return; } console.log('PUT request successful! Status:', response.statusCode); console.log('Response data:', data); });
Debug
Known issues
breakingxhr-request has not been updated in over seven years. It may contain security vulnerabilities from its unmaintained dependencies (xhr, simple-get) or from unpatched browser/Node.js HTTP stack issues. It is not recommended for new projects or sensitive applications.
fix
Migrate to actively maintained alternatives like `axios`, `node-fetch` (Node.js), or the built-in `fetch` API (browser).
affects: >=1.0.0
gotchaThe library is callback-based and does not natively support Promises or async/await syntax. Integrating it with modern asynchronous JavaScript patterns requires manual Promise wrapping.
fix
Wrap calls in a Promise: `new Promise((resolve, reject) => request(url, opts, (err, data) => err ? reject(err) : resolve(data)))`.
affects: >=1.0.0
gotchaxhr-request is a CommonJS module. Direct `import` statements in native ESM environments will fail, leading to `ERR_REQUIRE_ESM` or similar errors unless a bundler is used to transpile.
fix
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(...))`.
affects: >=1.0.0
gotchaThe package does not ship with TypeScript type definitions. Developers using TypeScript will need to create their own declaration files or use `@ts-ignore`.
fix
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).
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in a native ES Module environment (e.g., Node.js with `"type": "module"` or in a browser without a bundler).
fix
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.
TypeError: request is not a function
Incorrect import method for a CommonJS default export in some bundler configurations or when attempting to use named imports.
fix
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(...)`.
Error: self signed certificate in certificate chain
The underlying Node.js `simple-get` client (or `http` module) is encountering issues with self-signed or invalid SSL certificates on HTTPS connections.
fix
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.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
simple-getrequiredProvides HTTP request functionality for Node.js environments.
xhrrequiredProvides XMLHttpRequest functionality for browser environments.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
xhr-request — npm install xhr-request · libregistry