{"name":"httpreq","description":"node-httpreq is a node.js library to do HTTP(S) requests the easy way","version":"0.2.7","author":{"name":"Sam Decrock","url":"https://github.com/SamDecrock/"},"bugs":{"url":"https://github.com/SamDecrock/node-httpreq/issues"},"engines":{"node":">= 0.8.0"},"repository":{"type":"git","url":"git://github.com/SamDecrock/node-httpreq.git"},"main":"./httpreq","licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.php"}],"_id":"httpreq@0.2.7","dist":{"shasum":"2535dd85031a2ae45c1fb4cff06f87ca0e174a61","tarball":"http://registry-npm.ywwl.com/httpreq/download/httpreq-0.2.7.tgz","integrity":"sha512-6HOCfMswhRKLpG7qS6DKXDsLt5agKVB2uhAtT2PRXOL2hdg4vIdGG4+rC/pj7WC6SxEm8731eu3BiS/NVl0uQw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBMxwHmHgx5S5dtnrtTQzFWcfxk3d+u4klLHZm+K8k9nAiAgOxgHKZ9PR8X6K8Nk35ynOBZaQGBAL4VDzlz29kmKhA=="}],"size":65200,"noattachment":false,"key":"/httpreq/-/httpreq-0.2.7.tgz"},"_npmVersion":"1.1.49","_npmUser":{"name":"samdecrock","email":"sam.decrock@gmail.com"},"maintainers":[{"name":"samdecrock","email":"sam.decrock@gmail.com"}],"directories":{},"readme":"node-httpreq\n============\n\nnode-httpreq is a node.js library to do HTTP(S) requests the easy way\n\nDo GET, POST, PUT, PATCH, DELETE, OPTIONS, upload files, use cookies, change headers, ...\n\nThis module helps you fight [TLS fingerprinting](https://httptoolkit.com/blog/tls-fingerprinting-node-js/)! See the `shuffleCiphers` option below.\n\n## Donate\n\nIf you've benefited from this module in any way, please consider donating!\n\n[![](https://neat.be/paypal-donate-button.png)](https://www.paypal.com/donate/?hosted_button_id=2CKNJLZJBW8ZC)\n\nThank you for your support!\n\n\n## Install\n\nYou can install __httpreq__ using the Node Package Manager (npm):\n\n    npm install httpreq\n\n## Simple example\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.get('http://www.google.com', function (err, res) {\n  if (err) return console.log(err);\n\n  console.log(res.statusCode);\n  console.log(res.headers);\n  console.log(res.body);\n  console.log(res.cookies);\n});\n```\n\n__Using await/async:__\n\n```js\nvar httpreq = require('httpreq');\n\nvar res = await httpreq.get('http://www.google.com');\n\nconsole.log(res.statusCode);\nconsole.log(res.headers);\nconsole.log(res.body);\nconsole.log(res.cookies);\n```\n\n## Use with async/await\n\nThis module has been updated to support async/await.\n\nIn the following examples, simply omit the `callback` parameter and prepend it with `await`.\n\n__Example:__\n\n```js\nvar httpreq = require('httpreq');\n\nvar res = await httpreq.post('http://posttestserver.com/post.php', {\n  parameters: {\n    name: 'John',\n    lastname: 'Doe'\n  }\n});\n\nconsole.log(res.body);\n```\n\n## How to use\n\n* [httpreq.get(url, [options], callback)](#get)\n* [httpreq.post(url, [options], callback)](#post)\n* [httpreq.put(url, [options], callback)](#put)\n* [httpreq.delete(url, [options], callback)](#delete)\n* [httpreq.options(url, [options], callback)](#options)\n* [Uploading files](#upload)\n* [Downloading a binary file](#binary)\n* [Downloading a file directly to disk](#download)\n* [Sending a custom body](#custombody)\n* [Using a http(s) proxy](#proxy)\n* [httpreq.doRequest(options, callback)](#dorequest)\n\n---------------------------------------\n### httpreq.get(url, [options], callback)\n<a name=\"get\"></a>\n\n__Arguments__\n - url: The url to connect to. Can be http or https.\n - options: (all are optional) The following options can be passed:\n    - parameters: an object of query parameters\n    - headers: an object of headers\n    - cookies: an array of cookies\n    - auth: a string for basic authentication. For example `username:password`\n    - binary: true/false (default: false), if true, res.body will a buffer containing the binary data\n    - allowRedirects: (default: __true__ , only with httpreq.get() ), if true, redirects will be followed\n    - maxRedirects: (default: __10__ ). For example 1 redirect will allow for one normal request and 1 extra redirected request.\n    - timeout: (default: __none__ ). Adds a timeout to the http(s) request. Should be in milliseconds.\n    - ciphers: Change the TLS ciphers if needed.\n    - shuffleCiphers: Set to `true` if you want to shuffle the TLS ciphers to fight [TLS fingerprinting](https://httptoolkit.com/blog/tls-fingerprinting-node-js/).\n    - proxy, if you want to pass your request through a http(s) proxy server:\n        - host: eg: \"192.168.0.1\"\n        - port: eg: 8888\n        - protocol: (default: __'http'__ ) can be 'http' or 'https'\n     - rejectUnauthorized: validate certificate for request with HTTPS. [More here](http://nodejs.org/api/https.html#https_https_request_options_callback)\n - callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ), the http status code ( __res.statusCode__ ) and the body ( __res.body__ )\n\n__Example without options__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.get('http://www.google.com', function (err, res){\n  if (err) return console.log(err);\n\n  console.log(res.statusCode);\n  console.log(res.headers);\n  console.log(res.body);\n});\n```\n\n__Example with options__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.get('http://posttestserver.com/post.php', {\n  parameters: {\n    name: 'John',\n    lastname: 'Doe'\n  },\n  headers:{\n    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:18.0) Gecko/20100101 Firefox/18.0'\n  },\n  cookies: [\n    'token=DGcGUmplWQSjfqEvmu%2BZA%2Fc',\n    'id=2'\n  ]\n}, function (err, res){\n  if (err){\n    console.log(err);\n  }else{\n    console.log(res.body);\n  }\n});\n```\n---------------------------------------\n### httpreq.post(url, [options], callback)\n<a name=\"post\"></a>\n\n__Arguments__\n - url: The url to connect to. Can be http or https.\n - options: (all are optional) The following options can be passed:\n    - parameters: an object of post parameters (content-type is set to *application/x-www-form-urlencoded; charset=UTF-8*)\n    - json: if you want to send json directly (content-type is set to *application/json*)\n    - files: an object of files to upload (content-type is set to *multipart/form-data; boundary=xxx*)\n    - body: custom body content you want to send. If used, previous options will be ignored and your custom body will be sent. (content-type will not be set)\n    - headers: an object of headers\n    - cookies: an array of cookies\n    - auth: a string for basic authentication. For example `username:password`\n    - binary: true/false (default: __false__ ), if true, res.body will be a buffer containing the binary data\n    - allowRedirects: (default: __false__ ), if true, redirects will be followed\n    - maxRedirects: (default: __10__ ). For example 1 redirect will allow for one normal request and 1 extra redirected request.\n    - encodePostParameters: (default: __true__ ), if true, POST/PUT parameters names will be URL encoded.\n    - timeout: (default: none). Adds a timeout to the http(s) request. Should be in milliseconds.\n    - proxy, if you want to pass your request through a http(s) proxy server:\n        - host: eg: \"192.168.0.1\"\n        - port: eg: 8888\n        - protocol: (default: __'http'__ ) can be 'http' or 'https'\n    - rejectUnauthorized: validate certificate for request with HTTPS. [More here](http://nodejs.org/api/https.html#https_https_request_options_callback)\n - callback(err, res): A callback function which is called when the request is complete. __res__ contains the headers ( __res.headers__ ), the http status code ( __res.statusCode__ ) and the body ( __res.body__ )\n\n__Example without extra options__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.post('http://posttestserver.com/post.php', {\n  parameters: {\n    name: 'John',\n    lastname: 'Doe'\n  }\n}, function (err, res){\n  if (err){\n    console.log(err);\n  }else{\n    console.log(res.body);\n  }\n});\n```\n\n__Example with options__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.post('http://posttestserver.com/post.php', {\n  parameters: {\n    name: 'John',\n    lastname: 'Doe'\n  },\n  headers:{\n    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:18.0) Gecko/20100101 Firefox/18.0'\n  },\n  cookies: [\n    'token=DGcGUmplWQSjfqEvmu%2BZA%2Fc',\n    'id=2'\n  ]\n}, function (err, res){\n  if (err){\n    console.log(err);\n  }else{\n    console.log(res.body);\n  }\n});\n```\n\n---------------------------------------\n### httpreq.put(url, [options], callback)\n<a name=\"put\"></a>\n\nSame options as [httpreq.post(url, [options], callback)](#post)\n\n---------------------------------------\n<a name=\"delete\" />\n### httpreq.delete(url, [options], callback)\n\nSame options as [httpreq.post(url, [options], callback)](#post)\n\n---------------------------------------\n<a name=\"options\" />\n### httpreq.options(url, [options], callback)\n\nSame options as [httpreq.get(url, [options], callback)](#get) except for the ability to follow redirects.\n\n---------------------------------------\n<a name=\"upload\" />\n### Uploading files\n\nYou can still use ```httpreq.uploadFiles({url: 'url', files: {}}, callback)```, but it's easier to just use POST (or PUT):\n\n__Example__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.post('http://posttestserver.com/upload.php', {\n  parameters: {\n    name: 'John',\n    lastname: 'Doe'\n  },\n  files: {\n    myfile: __dirname + '/file1.jpg',\n    myotherfile: __dirname + '/file2.jpg'\n  }\n}, function (err, res){\n  if (err) throw err;\n});\n```\n\n__Example 2__\n\nIn case you want to use the same form name for multiple files:\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.post('http://posttestserver.com/upload.php', {\n  parameters: {\n    name: 'John',\n    lastname: 'Doe'\n  },\n  files: {\n    myfiles: [__dirname + '/file1.jpg', __dirname + '/file.jpg']\n  }\n}, function (err, res){\n  if (err) throw err;\n});\n```\n\n---------------------------------------\n<a name=\"binary\"></a>\n### Downloading a binary file\nTo download a binary file, just add __binary: true__ to the options when doing a get or a post.\n\n__Example__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.get('https://ssl.gstatic.com/gb/images/k1_a31af7ac.png', {binary: true}, function (err, res){\n  if (err){\n    console.log(err);\n  }else{\n    fs.writeFile(__dirname + '/test.png', res.body, function (err) {\n      if(err)\n        console.log(\"error writing file\");\n    });\n  }\n});\n```\n\n---------------------------------------\n<a name=\"download\"></a>\n### Downloading a file directly to disk\nTo download a file directly to disk, use the download method provided.\n\nDownloading is done using a stream, so the data is not stored in memory and directly saved to file.\n\n__Example__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.download(\n  'https://ssl.gstatic.com/gb/images/k1_a31af7ac.png',\n  __dirname + '/test.png'\n, function (err, progress){\n  if (err) return console.log(err);\n  console.log(progress);\n}, function (err, res){\n  if (err) return console.log(err);\n  console.log(res);\n});\n\n```\n\nWhen specifying the `progress` callback (3th parameter), you cannot use async/await.\n\n---------------------------------------\n<a name=\"custombody\"></a>\n### Sending a custom body\nUse the body option to send a custom body (eg. an xml post)\n\n__Example__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.post('http://posttestserver.com/post.php',{\n  body: '<?xml version=\"1.0\" encoding=\"UTF-8\"?>',\n  headers:{\n    'Content-Type': 'text/xml',\n  }},\n  function (err, res) {\n    if (err){\n      console.log(err);\n    }else{\n      console.log(res.body);\n    }\n  }\n);\n```\n\n---------------------------------------\n<a name=\"proxy\"></a>\n### Using a http(s) proxy\n\n__Example__\n\n```js\nvar httpreq = require('httpreq');\n\nhttpreq.post('http://posttestserver.com/post.php', {\n  proxy: {\n    host: '10.100.0.126',\n    port: 8888\n  }\n}, function (err, res){\n  if (err){\n    console.log(err);\n  }else{\n    console.log(res.body);\n  }\n});\n```\n\n---------------------------------------\n### httpreq.doRequest(options, callback)\n<a name=\"dorequest\"></a>\n\nhttpreq.doRequest is internally used by httpreq.get() and httpreq.post(). You can use this directly. Everything is stays the same as httpreq.get() or httpreq.post() except that the following options MUST be passed:\n- url: the url to post the files to\n- method: 'GET', 'POST', 'PUT' or 'DELETE'\n\n## Run tests\n\nInstall all depedencies with\n\n```bash\nnpm install\n```\n\nInstall mocha with\n\n```bash\nnpm install mocha -g\n```\n\nRun tests:\n```bash\nmocha test/tests.js\n```\n\nRun the async/await tests:\n```bash\nmocha test/tests-async.js\n```\n\n","publish_time":1362940987355,"_cnpm_publish_time":1362940987355,"dist-tags":{"latest":"1.1.1"}}