{"_id":"@bjoerge/xhr","_rev":"4-2779e184ab4bf79c914bfe73ac34d663","name":"@bjoerge/xhr","description":"small xhr abstraction","dist-tags":{"latest":"3.0.1"},"versions":{"3.0.0":{"name":"@bjoerge/xhr","version":"3.0.0","description":"small xhr abstraction","keywords":["xhr","http","xmlhttprequest","xhr2","browserify"],"author":{"name":"Raynos","email":"raynos2@gmail.com"},"repository":{"type":"git","url":"git://github.com/Raynos/xhr.git"},"main":"index","homepage":"https://github.com/Raynos/xhr","contributors":[{"name":"Jake Verbaten"}],"bugs":{"url":"https://github.com/Raynos/xhr/issues","email":"raynos2@gmail.com"},"dependencies":{"global":"~4.3.0","is-function":"^1.0.1","parse-headers":"^2.0.0","xtend":"^4.0.0"},"devDependencies":{"for-each":"^0.3.2","pre-commit":"1.0.10","run-browser":"github:naugtur/run-browser","tap-spec":"^4.0.2","tape":"^4.0.0"},"license":"MIT","scripts":{"test":"run-browser test/index.js -b -m test/mock-server.js | tap-spec","browser":"run-browser -m test/mock-server.js test/index.js"},"gitHead":"daa5846c3c419de9e8abeb14af2752378ac05618","_id":"@bjoerge/xhr@3.0.0","_shasum":"45210c295c95a81440bc863786ef278338cde209","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.5.0","_npmUser":{"name":"bjoerge","email":"bjoerge@gmail.com"},"dist":{"shasum":"45210c295c95a81440bc863786ef278338cde209","tarball":"https://registry.npmjs.org/@bjoerge/xhr/-/xhr-3.0.0.tgz","integrity":"sha512-8YELiK2WHPWCOjOlqutJeYFdsi7KHc8eObZRp06Ao9VwivGYGN20+dhCGV2J+3V1xryAE0GJclaumRPGNEdNLw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDeIhvplITPfQq4a3D1EGtMzvSbH7K/n830Krf1tjB1OQIgF3H9kptDhpZJFWYunhydL3ihhKNfx5XAu+LuZAhkA3g="}]},"maintainers":[{"name":"bjoerge","email":"bjoerge@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/xhr-3.0.0.tgz_1475829464024_0.6014262270182371"}},"3.0.1":{"name":"@bjoerge/xhr","version":"3.0.1","description":"small xhr abstraction","keywords":["xhr","http","xmlhttprequest","xhr2","browserify"],"author":{"name":"Raynos","email":"raynos2@gmail.com"},"repository":{"type":"git","url":"git://github.com/Raynos/xhr.git"},"main":"index","homepage":"https://github.com/Raynos/xhr","contributors":[{"name":"Jake Verbaten"}],"bugs":{"url":"https://github.com/Raynos/xhr/issues","email":"raynos2@gmail.com"},"dependencies":{"global":"~4.3.0","is-function":"^1.0.1","parse-headers":"^2.0.0","xtend":"^4.0.0"},"devDependencies":{"for-each":"^0.3.2","pre-commit":"1.0.10","run-browser":"github:naugtur/run-browser","tap-spec":"^4.0.2","tape":"^4.0.0"},"license":"MIT","scripts":{"test":"run-browser test/index.js -b -m test/mock-server.js | tap-spec","browser":"run-browser -m test/mock-server.js test/index.js"},"gitHead":"daa5846c3c419de9e8abeb14af2752378ac05618","_id":"@bjoerge/xhr@3.0.1","_shasum":"f25d5239e7fab6fd2412559334b519df7230db07","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.5.0","_npmUser":{"name":"bjoerge","email":"bjoerge@gmail.com"},"dist":{"shasum":"f25d5239e7fab6fd2412559334b519df7230db07","tarball":"https://registry.npmjs.org/@bjoerge/xhr/-/xhr-3.0.1.tgz","integrity":"sha512-41LOJKgN2NawhcPYYRuDVwkbS+cxYfufFXBmBc4DBzG0sSzpU90U57TOGf9LxzkP96mElg5pHqCSYmLSsiFlFg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC60HAOFHedDu8Z8bHJLYgl4AECBcgojqgbKntjSgsY2wIga4t5wlTZ+KVoWdeenpDCOtJOrZ4DTMKS/YUthUF3Scg="}]},"maintainers":[{"name":"bjoerge","email":"bjoerge@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/xhr-3.0.1.tgz_1475829950267_0.9028518835548311"}}},"readme":"# xhr\n\nA small XMLHttpRequest wrapper. Designed for use with [browserify](http://browserify.org/), [webpack](https://webpack.github.io/) etc.\n\nAPI is a subset of [request](https://github.com/request/request) so you can write code that works in both node.js and the browser by using `require('request')` in your code and telling your browser bundler to load `xhr` instead of `request`.\n\nFor browserify, add a [browser](https://github.com/substack/node-browserify#browser-field) field to your `package.json`:\n\n```\n\"browser\": {\n  \"request\": \"xhr\"\n}\n```\n\nFor webpack, add a [resolve.alias](http://webpack.github.io/docs/configuration.html#resolve-alias) field to your configuration:\n\n```\n\"resolve\": {\n  \"alias\": {\n    \"request$\": \"xhr\"\n  }\n}\n```\n\nBrowser support: IE8+ and everything else.\n\n## Example\n\n```js\nvar xhr = require(\"xhr\")\n\nxhr({\n    body: someJSONString,\n    uri: \"/foo\",\n    headers: {\n        \"Content-Type\": \"application/json\"\n    }\n}, function (err, resp, body) {\n    // check resp.statusCode\n})\n```\n\n## `var req = xhr(options, callback)`\n\n```js\ntype XhrOptions = String | {\n    useXDR: Boolean?,\n    sync: Boolean?,\n    uri: String,\n    url: String,\n    method: String?,\n    timeout: Number?,\n    headers: Object?,\n    body: String||Object?,\n    json: Boolean?,\n    username: String?,\n    password: String?,\n    withCredentials: Boolean?,\n    responseType: String?,\n    beforeSend: Function?\n}\nxhr := (XhrOptions, Callback<Response>) => Request\n```\nthe returned object is either an [`XMLHttpRequest`][3] instance\n    or an [`XDomainRequest`][4] instance (if on IE8/IE9 &&\n    `options.useXDR` is set to `true`)\n\nYour callback will be called once with the arguments\n    ( [`Error`][5], `response` , `body` ) where the response is an object:\n```js\n{\n    body: Object||String,\n    statusCode: Number,\n    method: String,\n    headers: {},\n    url: String,\n    rawRequest: xhr\n}\n```\n - `body`: HTTP response body - [`XMLHttpRequest.response`][6], [`XMLHttpRequest.responseText`][7] or\n    [`XMLHttpRequest.responseXML`][8] depending on the request type.\n - `rawRequest`: Original  [`XMLHttpRequest`][3] instance\n    or [`XDomainRequest`][4] instance (if on IE8/IE9 &&\n    `options.useXDR` is set to `true`)\n - `headers`: A collection of headers where keys are header names converted to lowercase\n\n\nYour callback will be called with an [`Error`][5] if there is an error in the browser that prevents sending the request.\nA HTTP 500 response is not going to cause an error to be returned.\n\n## Other signatures\n\n* `var req = xhr(url, callback)` -\na simple string instead of the options. In this case, a GET request will be made to that url.\n\n* `var req = xhr(url, options, callback)` -\nthe above may also be called with the standard set of options.\n\n### Convience methods\n* `var req = xhr.{post, put, patch, del, head, get}(url, callback)`\n* `var req = xhr.{post, put, patch, del, head, get}(options, callback)`\n* `var req = xhr.{post, put, patch, del, head, get}(url, options, callback)`\n\nThe `xhr` module has convience functions attached that will make requests with the given method.\nEach function is named after its method, with the exception of `DELETE` which is called `xhr.del` for compatibility.\n\nThe method shorthands may be combined with the url-first form of `xhr` for succinct and descriptive requests. For example,\n\n```js\nxhr.post('/post-to-me', function(err, resp) {\n  console.log(resp.body)\n})\n```\n\nor\n\n```js\nxhr.del('/delete-me', { headers: { my: 'auth' } }, function (err, resp) {\n  console.log(resp.statusCode);\n})\n```\n\n## Options\n\n### `options.method`\n\nSpecify the method the [`XMLHttpRequest`][3] should be opened\n    with. Passed to [`XMLHttpRequest.open`][2]. Defaults to \"GET\"\n\n### `options.useXDR`\n\nSpecify whether this is a cross origin (CORS) request for IE<10.\n    Switches IE to use [`XDomainRequest`][4] instead of `XMLHttpRequest`.\n    Ignored in other browsers.\n\nNote that headers cannot be set on an XDomainRequest instance.\n\n### `options.sync`\n\nSpecify whether this is a synchrounous request. Note that when\n    this is true the callback will be called synchronously. In\n    most cases this option should not be used. Only use if you\n    know what you are doing!\n\n### `options.body`\n\nPass in body to be send across the [`XMLHttpRequest`][3].\n    Generally should be a string. But anything that's valid as\n    a parameter to [`XMLHttpRequest.send`][1] should work  (Buffer for file, etc.).\n\nIf `options.json` is `true`, then this must be a JSON-serializable object.\n\n### `options.uri` or `options.url`\n\nThe uri to send a request to. Passed to [`XMLHttpRequest.open`][2]. `options.url` and `options.uri` are aliases for each other.\n\n### `options.headers`\n\nAn object of headers that should be set on the request. The\n    key, value pair is passed to [`XMLHttpRequest.setRequestHeader`][9]\n\n### `options.timeout`\n\nNumber of miliseconds to wait for response. Defaults to 0 (no timeout). Ignored when `options.sync` is true.\n\n### `options.json`\n\nIf set to `true` then we serialize the value of `options.body` and send that as the request body.\n    We also set the Content-Type to `\"application/json\"`.\n\nAdditionally the response body is parsed as JSON\n\n### `options.withCredentials`\n\nSpecify whether user credentials are to be included in a cross-origin\n    request. Sets [`XMLHttpRequest.withCredentials`][10]. Defaults to false.\n\nA wildcard `*` cannot be used in the `Access-Control-Allow-Origin` header when `withCredentials` is true.\n    The header needs to specify your origin explicitly or browser will abort the request.\n\n### `options.responseType`\n\nDetermines the data type of the `response`. Sets [`XMLHttpRequest.responseType`][11]. For example, a `responseType` of `document` will return a parsed `Document` object as the `response.body` for an XML resource.\n\n### `options.beforeSend`\n\nA function being called right before the `send` method of the `XMLHttpRequest` or `XDomainRequest` instance is called. The `XMLHttpRequest` or `XDomainRequest` instance is passed as an argument.\n\n### `options.xhr`\n\nPass an `XMLHttpRequest` object (or something that acts like one) to use instead of constructing a new one using the `XMLHttpRequest` or `XDomainRequest` constructors. Useful for testing.\n\n## FAQ\n\n- Why is my server's JSON response not parsed? I returned the right content-type.\n  - See `options.json` - you can set it to `true` on a GET request to tell `xhr` to parse the response body.\n  - Without `options.json` body is returned as-is (a string or when `responseType` is set and the browser supports it - a result of parsing JSON or XML)\n- How do I send an object or array as POST body?\n  - `options.body` should be a string or any other value that's valid as\n  a parameter to [`XMLHttpRequest.send`][1]. Any other value needs to\n  be serialized before passed to `xhr` for sending.\n  - To serialize to JSON you can set\n   `options.json` to `true` for convenience - then `xhr` will do the serialization and set content-type accordingly.\n- Where's stream API? `.pipe()` etc.\n  - Not implemented. You can't reasonably have that in the browser.\n\n\n## Mocking Requests\nYou can override the constructor used to create new requests for testing. When you're making a new request:\n\n```js\nxhr({ xhr: new MockXMLHttpRequest() })\n```\n\nor you can override the constructors used to create requests at the module level:\n\n```js\nxhr.XMLHttpRequest = MockXMLHttpRequest\nxhr.XDomainRequest = MockXDomainRequest\n```\n\n## MIT Licenced\n\n  [1]: http://xhr.spec.whatwg.org/#the-send()-method\n  [2]: http://xhr.spec.whatwg.org/#the-open()-method\n  [3]: http://xhr.spec.whatwg.org/#interface-xmlhttprequest\n  [4]: http://msdn.microsoft.com/en-us/library/ie/cc288060(v=vs.85).aspx\n  [5]: http://es5.github.com/#x15.11\n  [6]: http://xhr.spec.whatwg.org/#the-response-attribute\n  [7]: http://xhr.spec.whatwg.org/#the-responsetext-attribute\n  [8]: http://xhr.spec.whatwg.org/#the-responsexml-attribute\n  [9]: http://xhr.spec.whatwg.org/#the-setrequestheader()-method\n  [10]: http://xhr.spec.whatwg.org/#the-withcredentials-attribute\n  [11]: https://xhr.spec.whatwg.org/#the-responsetype-attribute\n","maintainers":[{"name":"bjoerge","email":"bjoerge@gmail.com"}],"time":{"modified":"2022-06-12T15:20:27.696Z","created":"2016-10-07T08:37:45.571Z","3.0.0":"2016-10-07T08:37:45.571Z","3.0.1":"2016-10-07T08:45:52.862Z"},"homepage":"https://github.com/Raynos/xhr","keywords":["xhr","http","xmlhttprequest","xhr2","browserify"],"repository":{"type":"git","url":"git://github.com/Raynos/xhr.git"},"contributors":[{"name":"Jake Verbaten"}],"author":{"name":"Raynos","email":"raynos2@gmail.com"},"bugs":{"url":"https://github.com/Raynos/xhr/issues","email":"raynos2@gmail.com"},"license":"MIT","readmeFilename":"README.md"}