{"_id":"reqwest-without-xhr2","_rev":"317150","name":"reqwest-without-xhr2","description":"A wrapper for asynchronous http requests","dist-tags":{"latest":"2.0.2"},"maintainers":[{"name":"afc163","email":""}],"time":{"modified":"2021-06-03T20:06:20.000Z","created":"2015-08-31T09:24:16.838Z","2.0.2":"2015-08-31T09:24:16.838Z"},"users":{},"author":{"name":"Dustin Diaz","email":"dustin@dustindiaz.com","url":"http://dustindiaz.com"},"repository":{"type":"git","url":"git+https://github.com/ded/reqwest.git"},"versions":{"2.0.2":{"name":"reqwest-without-xhr2","description":"A wrapper for asynchronous http requests","keywords":["ender","ajax","xhr","connection","web 2.0","async","sync"],"version":"2.0.2","homepage":"https://github.com/ded/reqwest","author":{"name":"Dustin Diaz","email":"dustin@dustindiaz.com","url":"http://dustindiaz.com"},"repository":{"type":"git","url":"git+https://github.com/ded/reqwest.git"},"main":"./reqwest.js","ender":"./src/ender.js","devDependencies":{"connect":"1.8.x","mime":"1.x.x","sink-test":">=0.1.2","dispatch":"0.x.x","valentine":">=1.4.7","smoosh":"0.4.0","delayed-stream":"0.0.5","bump":"0.2.3"},"scripts":{"boosh":"smoosh make ./build.json","test":"node ./test.js"},"license":"MIT","spm":{"main":"reqwest.js","ignore":["vendor","test","make"]},"gitHead":"46ec443c06737039a8e86856bd04becd05c4ddb4","bugs":{"url":"https://github.com/ded/reqwest/issues"},"_id":"reqwest-without-xhr2@2.0.2","_shasum":"a7346fb20ce9eb1d77c77e48dd8f53c9a80ce48d","_from":".","_npmVersion":"2.13.2","_nodeVersion":"2.5.0","_npmUser":{"name":"afc163","email":"afc163@gmail.com"},"maintainers":[{"name":"afc163","email":""}],"dist":{"shasum":"a7346fb20ce9eb1d77c77e48dd8f53c9a80ce48d","size":9353478,"noattachment":false,"key":"/reqwest-without-xhr2/-/reqwest-without-xhr2-2.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/reqwest-without-xhr2/download/reqwest-without-xhr2-2.0.2.tgz"},"directories":{},"publish_time":1441013056838,"_cnpm_publish_time":1441013056838,"_hasShrinkwrap":false}},"readme":"# It's AJAX\n\nAll over again. Includes support for xmlHttpRequest, JSONP, CORS, and CommonJS Promises A.\n\nIt is also isomorphic allowing you to `require('reqwest')` in `Node.js` through the peer dependency [xhr2](https://github.com/pwnall/node-xhr2), albeit the original intent of this library is for the browser. For a more thorough solution for Node.js, see [mikeal/request](https://github.com/request/request).\n\n## API\n\n``` js\nreqwest('path/to/html', function (resp) {\n  qwery('#content').html(resp)\n})\n\nreqwest({\n    url: 'path/to/html'\n  , method: 'post'\n  , data: { foo: 'bar', baz: 100 }\n  , success: function (resp) {\n      qwery('#content').html(resp)\n    }\n})\n\nreqwest({\n    url: 'path/to/html'\n  , method: 'get'\n  , data: [ { name: 'foo', value: 'bar' }, { name: 'baz', value: 100 } ]\n  , success: function (resp) {\n      qwery('#content').html(resp)\n    }\n})\n\nreqwest({\n    url: 'path/to/json'\n  , type: 'json'\n  , method: 'post'\n  , error: function (err) { }\n  , success: function (resp) {\n      qwery('#content').html(resp.content)\n    }\n})\n\nreqwest({\n    url: 'path/to/json'\n  , type: 'json'\n  , method: 'post'\n  , contentType: 'application/json'\n  , headers: {\n      'X-My-Custom-Header': 'SomethingImportant'\n    }\n  , error: function (err) { }\n  , success: function (resp) {\n      qwery('#content').html(resp.content)\n    }\n})\n\n// Uses XMLHttpRequest2 credentialled requests (cookies, HTTP basic auth) if supported\nreqwest({\n    url: 'path/to/json'\n  , type: 'json'\n  , method: 'post'\n  , contentType: 'application/json'\n  , crossOrigin: true\n  , withCredentials: true\n  , error: function (err) { }\n  , success: function (resp) {\n      qwery('#content').html(resp.content)\n    }\n})\n\nreqwest({\n    url: 'path/to/data.jsonp?callback=?'\n  , type: 'jsonp'\n  , success: function (resp) {\n      qwery('#content').html(resp.content)\n    }\n})\n\nreqwest({\n    url: 'path/to/data.jsonp?foo=bar'\n  , type: 'jsonp'\n  , jsonpCallback: 'foo'\n  , jsonpCallbackName: 'bar'\n  , success: function (resp) {\n      qwery('#content').html(resp.content)\n    }\n})\n\nreqwest({\n    url: 'path/to/data.jsonp?foo=bar'\n  , type: 'jsonp'\n  , jsonpCallback: 'foo'\n  , success: function (resp) {\n      qwery('#content').html(resp.content)\n    }\n  , complete: function (resp) {\n      qwery('#hide-this').hide()\n    }\n})\n```\n\n## Promises\n\n``` js\nreqwest({\n    url: 'path/to/data.jsonp?foo=bar'\n  , type: 'jsonp'\n  , jsonpCallback: 'foo'\n})\n  .then(function (resp) {\n    qwery('#content').html(resp.content)\n  }, function (err, msg) {\n    qwery('#errors').html(msg)\n  })\n  .always(function (resp) {\n    qwery('#hide-this').hide()\n  })\n```\n\n``` js\nreqwest({\n    url: 'path/to/data.jsonp?foo=bar'\n  , type: 'jsonp'\n  , jsonpCallback: 'foo'\n})\n  .then(function (resp) {\n    qwery('#content').html(resp.content)\n  })\n  .fail(function (err, msg) {\n    qwery('#errors').html(msg)\n  })\n  .always(function (resp) {\n    qwery('#hide-this').hide()\n  })\n```\n\n``` js\nvar r = reqwest({\n    url: 'path/to/data.jsonp?foo=bar'\n  , type: 'jsonp'\n  , jsonpCallback: 'foo'\n  , success: function () {\n      setTimeout(function () {\n        r\n          .then(function (resp) {\n            qwery('#content').html(resp.content)\n          }, function (err) { })\n          .always(function (resp) {\n             qwery('#hide-this').hide()\n          })\n      }, 15)\n    }\n})\n```\n\n## Options\n\n  * `url` a fully qualified uri\n  * `method` http method (default: `GET`)\n  * `headers` http headers (default: `{}`)\n  * `data` entity body for `PATCH`, `POST` and `PUT` requests. Must be a query `String` or `JSON` object\n  * `type` a string enum. `html`, `xml`, `json`, or `jsonp`. Default is inferred by resource extension. Eg: `.json` will set `type` to `json`. `.xml` to `xml` etc.\n  * `contentType` sets the `Content-Type` of the request. Eg: `application/json`\n  * `crossOrigin` for cross-origin requests for browsers that support this feature.\n  * `success` A function called when the request successfully completes\n  * `error` A function called when the request fails.\n  * `complete` A function called whether the request is a success or failure. Always called when complete.\n  * `jsonpCallback` Specify the callback function name for a `JSONP` request. This value will be used instead of the random (but recommended) name automatically generated by reqwest.\n\n## Security\n\nIf you are *still* requiring support for IE6/IE7, consider including [JSON3](https://bestiejs.github.io/json3/) in your project. Or simply do the following\n\n``` html\n<script>\n(function () {\n  if (!window.JSON) {\n    document.write('<scr' + 'ipt src=\"http://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js\"><\\/scr' + 'ipt>')\n  }\n}());\n</script>\n```\n\n\n## Contributing\n\n``` sh\n$ git clone git://github.com/ded/reqwest.git reqwest\n$ cd !$\n$ npm install\n```\n\nPlease keep your local edits to `src/reqwest.js`.\nThe base `./reqwest.js` and `./reqwest.min.js` will be built upon releases.\n\n## Running Tests\n\n``` sh\nmake test\n```\n\n## Browser support\n\n  * IE6+\n  * Chrome 1+\n  * Safari 3+\n  * Firefox 1+\n  * Opera\n\n## Ender Support\nReqwest can be used as an [Ender](http://enderjs.com) module. Add it to your existing build as such:\n\n    $ ender add reqwest\n\nUse it as such:\n\n``` js\n$.ajax({ ... })\n```\n\nSerialize things:\n\n``` js\n$(form).serialize() // returns query string -> x=y&...\n$(form).serialize({type:'array'}) // returns array name/value pairs -> [ { name: x, value: y}, ... ]\n$(form).serialize({type:'map'}) // returns an object representation -> { x: y, ... }\n$(form).serializeArray()\n$.toQueryString({\n    foo: 'bar'\n  , baz: 'thunk'\n}) // returns query string -> foo=bar&baz=thunk\n```\n\nOr, get a bit fancy:\n\n``` js\n$('#myform input[name=myradios]').serialize({type:'map'})['myradios'] // get the selected value\n$('input[type=text],#specialthing').serialize() // turn any arbitrary set of form elements into a query string\n```\n\n## ajaxSetup\nUse the `request.ajaxSetup` to predefine a data filter on all requests. See the example below that demonstrates JSON hijacking prevention:\n\n``` js\n$.ajaxSetup({\n  dataFilter: function (response, type) {\n    if (type == 'json') return response.substring('])}while(1);</x>'.length)\n    else return response\n  }\n})\n```\n\n## RequireJs and Jam\nReqwest can also be used with RequireJs and can be installed via jam\n\n```\njam install reqwest\n```\n\n```js\ndefine(function(require){\n  var reqwest = require('reqwest')\n});\n```\n\n## spm\nReqwest can also be installed via spm [![](http://spmjs.io/badge/reqwest)](http://spmjs.io/package/reqwest)\n\n```\nspm install reqwest\n```\n\n## jQuery and Zepto Compatibility\nThere are some differences between the *Reqwest way* and the\n*jQuery/Zepto way*.\n\n### method ###\njQuery/Zepto use `type` to specify the request method while Reqwest uses\n`method` and reserves `type` for the response data type.\n\n### dataType ###\nWhen using jQuery/Zepto you use the `dataType` option to specify the type\nof data to expect from the server, Reqwest uses `type`. jQuery also can\nalso take a space-separated list of data types to specify the request,\nresponse and response-conversion types but Reqwest uses the `type`\nparameter to infer the response type and leaves conversion up to you.\n\n### JSONP ###\nReqwest also takes optional `jsonpCallback` and `jsonpCallbackName`\noptions to specify the callback query-string key and the callback function\nname respectively while jQuery uses `jsonp` and `jsonpCallback` for\nthese same options.\n\n\nBut fear not! If you must work the jQuery/Zepto way then Reqwest has\na wrapper that will remap these options for you:\n\n```js\nreqwest.compat({\n    url: 'path/to/data.jsonp?foo=bar'\n  , dataType: 'jsonp'\n  , jsonp: 'foo'\n  , jsonpCallback: 'bar'\n  , success: function (resp) {\n      qwery('#content').html(resp.content)\n    }\n})\n\n// or from Ender:\n\n$.ajax.compat({\n  ...\n})\n```\n\nIf you want to install jQuery/Zepto compatibility mode as the default\nthen simply place this snippet at the top of your code:\n\n```js\n$.ajax.compat && $.ender({ ajax: $.ajax.compat });\n```\n\n\n**Happy Ajaxing!**\n","_attachments":{},"homepage":"https://github.com/ded/reqwest","bugs":{"url":"https://github.com/ded/reqwest/issues"},"license":"MIT"}