{"_id":"xhr-request","_rev":"4628430","name":"xhr-request","description":"tiny http client for Node and the browser","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"time":{"modified":"2026-04-10T18:44:04.000Z","created":"2015-09-01T22:44:02.206Z","1.1.0":"2018-02-03T17:31:27.852Z","1.0.1":"2015-09-02T14:42:31.559Z","1.0.0":"2015-09-01T22:44:02.206Z"},"users":{},"author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"repository":{"type":"git","url":"git://github.com/Jam3/xhr-request.git"},"versions":{"1.1.0":{"name":"xhr-request","version":"1.1.0","description":"tiny http client for Node and the browser","main":"index.js","license":"MIT","browser":{"./lib/request.js":"./lib/request-browser.js"},"author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"buffer-to-arraybuffer":"^0.0.5","object-assign":"^4.1.1","query-string":"^5.0.1","simple-get":"^2.7.0","timed-out":"^4.0.1","url-set-query":"^1.0.0","xhr":"^2.0.4"},"devDependencies":{"budo":"^11.0.1","faucet":"0.0.1","standard":"^10.0.3","tape":"^4.0.1"},"scripts":{"test":"standard && npm run test-node && npm run test-browser","test-node":"node test/index.js | faucet","test-browser":"budo test/test-browser.js -o"},"keywords":["node","browser","http","got","request","gots","nets","xhr","xmlhttprequest","xml","http","request","client","https","requests","xml","get","query","string"],"repository":{"type":"git","url":"git://github.com/Jam3/xhr-request.git"},"homepage":"https://github.com/Jam3/xhr-request","bugs":{"url":"https://github.com/Jam3/xhr-request/issues"},"gitHead":"5154750cd3b178cd30d1f65fd955e68838f92b89","_id":"xhr-request@1.1.0","_npmVersion":"5.6.0","_nodeVersion":"8.4.0","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"f4a7c1868b9f198723444d82dcae317643f2e2ed","size":4331,"noattachment":false,"key":"/xhr-request/-/xhr-request-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/xhr-request/download/xhr-request-1.1.0.tgz"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/xhr-request-1.1.0.tgz_1517679087679_0.745320345275104"},"directories":{},"publish_time":1517679087852,"_hasShrinkwrap":false,"_cnpm_publish_time":1517679087852,"_cnpmcore_publish_time":"2021-12-16T18:20:47.423Z"},"1.0.1":{"name":"xhr-request","version":"1.0.1","description":"tiny http client for Node and the browser","main":"index.js","license":"MIT","browser":{"./lib/request.js":"./lib/request-browser.js"},"author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"buffer-to-arraybuffer":"0.0.2","object-assign":"^3.0.0","query-string":"^2.4.0","simple-get":"^1.4.3","timed-out":"^2.0.0","url-set-query":"^1.0.0","xhr":"^2.0.4"},"devDependencies":{"faucet":"0.0.1","hihat":"^2.4.3","standard":"^5.1.1","tape":"^4.0.1"},"scripts":{"test":"standard && npm run test-node && npm run test-browser","test-node":"node test/index.js | faucet","test-browser":"hihat test/test-browser.js --timeout=3000 --quit --print | faucet"},"keywords":["node","browser","http","got","request","gots","nets","xhr","xmlhttprequest","xml","http","request","client","https","requests","xml","get","query","string"],"repository":{"type":"git","url":"git://github.com/Jam3/xhr-request.git"},"homepage":"https://github.com/Jam3/xhr-request","bugs":{"url":"https://github.com/Jam3/xhr-request/issues"},"gitHead":"45974a4a55a148a3686245e32bc2d9f550334b1f","_id":"xhr-request@1.0.1","_shasum":"83f08a4b20beec67a8c1c728e8102f4c9eecbdda","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"83f08a4b20beec67a8c1c728e8102f4c9eecbdda","size":4213,"noattachment":false,"key":"/xhr-request/-/xhr-request-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/xhr-request/download/xhr-request-1.0.1.tgz"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"directories":{},"publish_time":1441204951559,"_hasShrinkwrap":false,"_cnpm_publish_time":1441204951559,"_cnpmcore_publish_time":"2021-12-16T18:20:47.686Z"},"1.0.0":{"name":"xhr-request","version":"1.0.0","description":"tiny http client for Node and the browser","main":"index.js","license":"MIT","browser":{"./lib/request.js":"./lib/request-browser.js"},"author":{"name":"Matt DesLauriers","email":"dave.des@gmail.com","url":"https://github.com/mattdesl"},"dependencies":{"buffer-to-arraybuffer":"0.0.2","object-assign":"^3.0.0","query-string":"^2.4.0","simple-get":"^1.4.3","timed-out":"^2.0.0","url-set-query":"^1.0.0","xhr":"^2.0.4"},"devDependencies":{"faucet":"0.0.1","hihat":"^2.4.3","standard":"^5.1.1","tape":"^4.0.1"},"scripts":{"test":"standard && npm run test-node && npm run test-browser","test-node":"node test/index.js | faucet","test-browser":"hihat test/test-browser.js --timeout=3000 --quit --print | faucet"},"keywords":["node","browser","http","got","request","gots","nets","xhr","xmlhttprequest","xml","http","request","client","https","requests","xml","get","query","string"],"repository":{"type":"git","url":"git://github.com/Jam3/xhr-request.git"},"homepage":"https://github.com/Jam3/xhr-request","bugs":{"url":"https://github.com/Jam3/xhr-request/issues"},"gitHead":"0d8f8da75225fd89824a3e9c892851343de51a80","_id":"xhr-request@1.0.0","_shasum":"4b5d580dc0f45604ce65a98272bce35d7c705145","_from":".","_npmVersion":"2.1.18","_nodeVersion":"0.10.32","_npmUser":{"name":"mattdesl","email":"dave.des@gmail.com"},"dist":{"shasum":"4b5d580dc0f45604ce65a98272bce35d7c705145","size":4088,"noattachment":false,"key":"/xhr-request/-/xhr-request-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/xhr-request/download/xhr-request-1.0.0.tgz"},"maintainers":[{"name":"mattdesl","email":"dave.des@gmail.com"}],"directories":{},"publish_time":1441147442206,"_hasShrinkwrap":false,"_cnpm_publish_time":1441147442206,"_cnpmcore_publish_time":"2021-12-16T18:20:47.898Z"}},"readme":"# xhr-request\n\n[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)\n\nAn extremely tiny HTTP/HTTPS request client for Node and the browser. Uses [xhr](https://www.npmjs.com/package/xhr) in the browser and [simple-get](https://www.npmjs.com/package/simple-get) in Node. \n\nSupported response types: JSON, ArrayBuffer, and text (default).\n\nFor streaming requests, you can just use [simple-get](https://www.npmjs.com/package/simple-get) directly. It works in Node/browser and supports true streaming in new versions of Chrome/FireFox.\n\n## Install\n\n```sh\nnpm install xhr-request --save\n```\n\n## Example\n\nA simple example, loading JSON:\n\n```js\nvar request = require('xhr-request')\n\nrequest('http://foo.com/some/api', {\n  json: true\n}, function (err, data) {\n  if (err) throw err\n  \n  // the JSON result\n  console.log(data.foo.bar)\n})\n```\n\nAnother example, sending a JSON `body` with a `query` parameter. Receives binary data as the response.\n\n```js\nvar request = require('xhr-request')\n\nrequest('http://foo.com/some/api', {\n  method: 'PUT',\n  json: true,\n  body: { foo: 'bar' },\n  responseType: 'arraybuffer',\n  query: {\n    sort: 'name'\n  }\n}, function (err, data) {\n  if (err) throw err\n  console.log('got ArrayBuffer result: ', data)\n})\n```\n\n## Motivation\n\nThere are a lot of HTTP clients, but most of them are Node-centric and lead to large browser bundles with builtins like `url`, `buffer`, `http`, `zlib`, streams, etc. \n\nWith browserify, this bundles to 7kb minified. Compare to 742kb for [request](https://www.npmjs.com/package/request), 153kb for [got](https://www.npmjs.com/package/got), 74kb for [simple-get](https://www.npmjs.com/package/simple-get), and 25kb for [nets](https://www.npmjs.com/package/nets).\n\n## Usage\n\n#### `req = xhrRequest(url, [opt], [callback])`\n\nSends a request to the given `url` with optional `opt` settings, triggering `callback` on complete.\n\nOptions:\n\n- `query` (String|Object)\n  - the query parameters to use for the URL\n- `headers` (Object)\n  - the headers for the request\n- `json` (Boolean) \n  - if true, `responseType` defaults to `'json`' and `body` will be sent as JSON\n- `responseType` (String)\n  - can be `'text'`, `'arraybuffer'` or `'json'`\n  - defaults to `'text'` unless `json` is true\n- `body` (String|JSON)\n  - an optional body to send with request\n  - sent as text unless `json` is true\n- `method` (String)\n  - an optional method to use, defaults to `'GET'`\n- `timeout` (Number)\n  - milliseconds to use as a timeout, defaults to 0 (no timeout)\n\nThe `callback` is called with the arguments `(error, data, response)`\n\n- `error` on success will be null/undefined\n- `data` the result of the request, either a JSON object, string, or `ArrayBuffer`\n- `response` the request response, see below\n\nThe response object has the following form:\n\n```js\n{\n  statusCode: Number,\n  method: String,\n  headers: {},\n  url: String,\n  rawRequest: {}\n}\n```\n\nThe `rawRequest` is the XMLHttpRequest in the browser, and the `http` response in Node.\n\nSince `opt` is optional, you can specify `callback` as the second argument.\n\n#### `req.abort()`\n\nThe returned `req` (the [ClientRequest](https://nodejs.org/api/http.html#http_class_http_clientrequest) or XMLHttpRequest) has an `abort()` method which can be used to cancel the request and send an Error to the callback.\n\n## See Also\n\n- [simple-get](https://www.npmjs.com/package/simple-get)\n- [xhr](https://www.npmjs.com/package/xhr)\n- [got](https://www.npmjs.com/package/got)\n- [nets](https://www.npmjs.com/package/nets)\n- [superagent](https://www.npmjs.com/package/nets)\n- [axios](https://www.npmjs.com/package/axios)\n\n## License\n\nMIT, see [LICENSE.md](http://github.com/Jam3/xhr-request/blob/master/LICENSE.md) for details.\n","_attachments":{},"homepage":"https://github.com/Jam3/xhr-request","bugs":{"url":"https://github.com/Jam3/xhr-request/issues"},"license":"MIT"}