{"id":14375,"library":"xhr-request","title":"Tiny Universal HTTP Client (xhr-request)","description":"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.","status":"abandoned","version":"1.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/Jam3/xhr-request","tags":["javascript","node","browser","http","got","request","gots","nets","xhr"],"install":[{"cmd":"npm install xhr-request","lang":"bash","label":"npm"},{"cmd":"yarn add xhr-request","lang":"bash","label":"yarn"},{"cmd":"pnpm add xhr-request","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides HTTP request functionality for Node.js environments.","package":"simple-get","optional":false},{"reason":"Provides XMLHttpRequest functionality for browser environments.","package":"xhr","optional":false}],"imports":[{"note":"xhr-request is a CommonJS module. Direct ESM import will fail without a bundler or dynamic import.","wrong":"import request from 'xhr-request'","symbol":"request","correct":"const request = require('xhr-request')"},{"note":"As a JavaScript-only library without TypeScript types, callbacks are typically documented with JSDoc.","symbol":"RequestCallback","correct":"/** @param {function(Error|null, any, object)} callback */"}],"quickstart":{"code":"const request = require('xhr-request')\n\n// Example: Loading JSON data from an API\nrequest('https://api.github.com/users/octocat', { json: true }, function (err, data) {\n  if (err) {\n    console.error('Error fetching user data:', err);\n    return;\n  }\n  console.log('GitHub User (Octocat):', data.login);\n  console.log('Followers:', data.followers);\n});\n\n// Example: Sending a PUT request with a JSON body and query parameters\n// Note: This URL will likely fail with a 404/405 as it's a dummy endpoint.\nrequest('https://httpbin.org/put', {\n  method: 'PUT',\n  json: true,\n  body: { status: 'active', user: 'testuser' },\n  query: { id: '123', region: 'us-east' },\n  headers: { 'X-Custom-Header': 'my-value' }\n}, function (err, data, response) {\n  if (err) {\n    console.error('Error in PUT request:', err);\n    return;\n  }\n  console.log('PUT request successful! Status:', response.statusCode);\n  console.log('Response data:', data);\n});","lang":"javascript","description":"Demonstrates fetching JSON data and sending a PUT request with JSON body and query parameters using the callback-based API."},"warnings":[{"fix":"Migrate to actively maintained alternatives like `axios`, `node-fetch` (Node.js), or the built-in `fetch` API (browser).","message":"xhr-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.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Wrap calls in a Promise: `new Promise((resolve, reject) => request(url, opts, (err, data) => err ? reject(err) : resolve(data)))`.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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(...))`.","message":"xhr-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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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).","message":"The package does not ship with TypeScript type definitions. Developers using TypeScript will need to create their own declaration files or use `@ts-ignore`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.0':27 'abandon':104 'achiev':48 'activ':108 'ago':42 'applic':117 'arraybuff':75 'basic':82 'bodi':92 'browser':22,65,139 'bundl':46,123 'cadenc':110 'client':4,16 'compact':14 'compar':52 'concern':136 'constrain':120 'contemporari':54 'current':24 'design':17 'differenti':30 'environ':23,121 'especi':31 'extrem':13 'featur':129 'get':69 'got':58,141,143 'header':86 'high':119 'http':3,140 'http/https':15 'impli':102 'intellig':60 'javascript':137 'json':74 'last':37 'legaci':116 'leverag':61 'like':55 'main':114 'make':111 'mani':100 'method':85 'minim':45 'modern':128 'net':144 'node':138 'node.js':20,71 'offer':81 'option':83 'output':51 'paramet':88 'paramount':126 'primari':29 'project':94 'queri':87 'receiv':97 'releas':109 'request':7,10,56,91,142 'respons':78 'secur':131 'seven':40 'signific':49 'simpl':68 'simple-get':67 'size':47,124 'smaller':50 'status':105 'suitabl':113 'support':73 'text':77 'time':34 'tini':1 'type':79 'univers':2 'updat':38,98,132 'version':26 'xhr':6,9,62,145 'xhr-request':5,8 'year':41,101","created_at":"2026-04-20T01:59:23.341634+00:00","updated_at":"2026-04-20T01:59:23.341634+00:00","problems":[{"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.","cause":"Attempting to use `require()` in a native ES Module environment (e.g., Node.js with `\"type\": \"module\"` or in a browser without a bundler).","error":"ReferenceError: require is not defined"},{"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(...)`.","cause":"Incorrect import method for a CommonJS default export in some bundler configurations or when attempting to use named imports.","error":"TypeError: request is not a function"},{"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.","cause":"The underlying Node.js `simple-get` client (or `http` module) is encountering issues with self-signed or invalid SSL certificates on HTTPS connections.","error":"Error: self signed certificate in certificate chain"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Jam3/xhr-request","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/xhr-request","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}