{"name":"simple-get","description":"Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines.","version":"2.2.2","author":{"name":"Feross Aboukhadijeh","email":"feross@feross.org","url":"http://feross.org/"},"browser":{"unzip-response":false},"bugs":{"url":"https://github.com/feross/simple-get/issues"},"dependencies":{"once":"^1.3.1","unzip-response":"^1.0.0","xtend":"^4.0.0"},"devDependencies":{"concat-stream":"^1.4.7","self-signed-https":"^1.0.5","standard":"^7.0.1","string-to-stream":"^1.0.0","tape":"^4.0.0"},"homepage":"https://github.com/feross/simple-get","keywords":["request","http","GET","get request","http.get","redirects","follow redirects","gzip","deflate","https","http-https","stream","simple request","simple get"],"license":"MIT","main":"index.js","repository":{"type":"git","url":"git://github.com/feross/simple-get.git"},"scripts":{"test":"standard && tape test/*.js"},"gitHead":"5cd9379bcb62575f79dbfea6ce24adbca611fa6c","_id":"simple-get@2.2.2","_shasum":"e4d0ff30af7dddf8ef9b5221c32658e7f1438515","_from":".","_npmVersion":"3.8.9","_nodeVersion":"6.2.0","_npmUser":{"name":"feross","email":"feross@feross.org"},"dist":{"shasum":"e4d0ff30af7dddf8ef9b5221c32658e7f1438515","tarball":"http://registry-npm.ywwl.com/simple-get/download/simple-get-2.2.2.tgz","integrity":"sha512-NubLRlXIeFSAomz28LbR7M0cXOQKRYSNtdFbKKjqDWXtxJCv9QeNjyLSkOcLLKoth9n7NlPIiWehj3R5nQ87xg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDfN0Gl0ZnounWbBsru8KycGMh4uEedi/Yfpojh2M1yUgIgE/Az5Ish8J8eNDWxtln9f4cWdOyXbre6BweQDVXmPlI="}],"size":4962,"noattachment":false,"key":"/simple-get/-/simple-get-2.2.2.tgz"},"maintainers":[{"name":"feross","email":"feross@feross.org"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/simple-get-2.2.2.tgz_1468355064847_0.09573076432570815"},"directories":{},"readme":"# simple-get [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[travis-image]: https://img.shields.io/travis/feross/simple-get/master.svg\n[travis-url]: https://travis-ci.org/feross/simple-get\n[npm-image]: https://img.shields.io/npm/v/simple-get.svg\n[npm-url]: https://npmjs.org/package/simple-get\n[downloads-image]: https://img.shields.io/npm/dm/simple-get.svg\n[downloads-url]: https://npmjs.org/package/simple-get\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### Simplest way to make http get requests\n\n## features\n\nThis module is the lightest possible wrapper on top of node.js `http`, but supporting these essential features:\n\n- follows redirects\n- automatically handles gzip/deflate responses\n- supports HTTPS\n- supports specifying a timeout\n- supports convenience `url` key so there's no need to use `url.parse` on the url when specifying options\n- composes well with npm packages for features like cookies, proxies, form data, & OAuth\n\nAll this in < 120 lines of code.\n\n## install\n\n```\nnpm install simple-get\n```\n\n## usage\n\nNote, all these examples also work in the browser with [browserify](http://browserify.org/).\n\n### simple GET request\n\nDoesn't get easier than this:\n\n```js\nconst get = require('simple-get')\n\nget('http://example.com', function (err, res) {\n  if (err) throw err\n  console.log(res.statusCode) // 200\n  res.pipe(process.stdout) // `res` is a stream\n})\n```\n\n### even simpler GET request\n\nIf you just want the data, and don't want to deal with streams:\n\n```js\nconst get = require('simple-get')\n\nget.concat('http://example.com', function (err, res, data) {\n  if (err) throw err\n  console.log(res.statusCode) // 200\n  console.log(data) // Buffer('this is the server response')\n})\n```\n\n### POST, PUT, PATCH, HEAD, DELETE support\n\nFor `POST`, call `get.post` or use option `{ method: 'POST' }`.\n\n```js\nconst get = require('simple-get')\n\nconst opts = {\n  url: 'http://example.com',\n  body: 'this is the POST body'\n}\nget.post(opts, function (err, res) {\n  if (err) throw err\n  res.pipe(process.stdout) // `res` is a stream\n})\n```\n\n#### A more complex example:\n\n```js\nconst get = require('simple-get')\n\nget({\n  url: 'http://example.com',\n  method: 'POST',\n  body: 'this is the POST body',\n\n  // simple-get accepts all options that node.js `http` accepts\n  // See: http://nodejs.org/api/http.html#http_http_request_options_callback\n  headers: {\n    'user-agent': 'my cool app'\n  }\n}, function (err, res) {\n  if (err) throw err\n\n  // All properties/methods from http.IncomingResponse are available,\n  // even if a gunzip/inflate transform stream was returned.\n  // See: http://nodejs.org/api/http.html#http_http_incomingmessage\n  res.setTimeout(10000)\n  console.log(res.headers)\n\n  res.on('data', function (chunk) {\n    // `chunk` is the decoded response, after it's been gunzipped or inflated\n    // (if applicable)\n    console.log('got a chunk of the response: ' + chunk)\n  }))\n\n})\n```\n\n### JSON\n\nYou can serialize/deserialize request and response with JSON:\n\n```js\nconst get = require('simple-get')\n\nconst opts = {\n  method: 'POST',\n  url: 'http://example.com',\n  body: {\n    key: 'value'\n  },\n  json: true\n}\nget.concat(opts, function (err, res, data) {\n  if (err) throw err\n  console.log(data.key) // `data` is an object\n})\n```\n\n### Timeout\n\nYou can set a timeout (in milliseconds) on the request with the `timeout` option.\nIf the request takes longer than `timeout` to complete, then the entire request\nwill fail with an `Error`.\n\n```js\nconst get = require('simple-get')\n\nconst opts = {\n  url: 'http://example.com',\n  timeout: 2000 // 2 second timeout\n}\n\nget(opts, function (err, res) {})\n```\n\n### One Quick Tip\n\nIt's a good idea to set the `'user-agent'` header so the provider can more easily\nsee how their resource is used.\n\n```js\nconst get = require('simple-get')\nconst pkg = require('./package.json')\n\nget('http://example.com', {\n  headers: {\n    'user-agent': `my-module/${pkg.version} (https://github.com/username/my-module)`\n  }\n})\n```\n\n### Proxies\n\nYou can use the [`tunnel`](https://github.com/koichik/node-tunnel) module with the\n`agent` option to work with proxies:\n\n```js\nconst get = require('simple-get')\nconst tunnel = require('tunnel')\n\nconst opts = {\n  url: 'http://example.com',\n  agent: tunnel.httpOverHttp({\n    proxy: {\n      host: 'localhost'\n    }\n  })\n}\n\nget(opts, function (err, res) {})\n```\n\n### Cookies\n\nYou can use the [`cookie`](https://github.com/jshttp/cookie) module to include\ncookies in a request:\n\n```js\nconst get = require('simple-get')\nconst cookie = require('cookie')\n\nconst opts = {\n  url: 'http://example.com',\n  headers: {\n    cookie: cookie.serialize('foo', 'bar')\n  }\n}\n\nget(opts, function (err, res) {})\n```\n\n### Form data\n\nYou can use the [`form-data`](https://github.com/form-data/form-data) module to\ncreate POST request with form data:\n\n```js\nconst fs = require('fs')\nconst get = require('simple-get')\nconst FormData = require('form-data')\nconst form = new FormData()\n\nform.append('my_file', fs.createReadStream('/foo/bar.jpg'))\n\nconst opts = {\n  url: 'http://example.com',\n  body: form\n}\n\nget.post(opts, function (err, res) {})\n```\n\n#### Or, include `application/x-www-form-urlencoded` form data manually:\n\n```js\nconst get = require('simple-get')\n\nconst opts = {\n  url: 'http://example.com',\n  form: {\n    key: 'value'\n  }\n}\nget.post(opts, function (err, res) {})\n```\n\n### OAuth\n\nYou can use the [`oauth-1.0a`](https://github.com/ddo/oauth-1.0a) module to create\na signed OAuth request:\n\n```js\nconst get = require('simple-get')\nconst crypto  = require('crypto')\nconst OAuth = require('oauth-1.0a')\n\nconst oauth = OAuth({\n  consumer: {\n    key: process.env.CONSUMER_KEY,\n    secret: process.env.CONSUMER_SECRET\n  },\n  signature_method: 'HMAC-SHA1',\n  hash_function: (baseString, key) => crypto.createHmac('sha1', key).update(baseString).digest('base64')\n})\n\nconst token = {\n  key: process.env.ACCESS_TOKEN,\n  secret: process.env.ACCESS_TOKEN_SECRET\n}\n\nconst url = 'https://api.twitter.com/1.1/statuses/home_timeline.json'\n\nconst opts = {\n  url: url,\n  headers: oauth.toHeader(oauth.authorize({url, method: 'GET'}, token)),\n  json: true\n}\n\nget(opts, function (err, res) {})\n```\n\n### Throttle requests\n\nYou can use [limiter](https://github.com/jhurliman/node-rate-limiter) to throttle requests. This is useful when calling an API that is rate limited.\n\n```js\nconst simpleGet = require('simple-get')\nconst RateLimiter = require('limiter').RateLimiter\nconst limiter = new RateLimiter(1, 'second')\n\nconst get = (opts, cb) => limiter.removeTokens(1, () => simpleGet(opts, cb))\nget.concat = (opts, cb) => limiter.removeTokens(1, () => simpleGet.concat(opts, cb))\n\nvar opts = {\n  url: 'http://example.com'\n}\n\nget.concat(opts, processResult)\nget.concat(opts, processResult)\n\nfunction processResult (err, res, data) {\n  if (err) throw err\n  console.log(data.toString())\n}\n```\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).\n","publish_time":1468355065336,"_cnpm_publish_time":1468355065336,"dist-tags":{"latest":"4.0.1"}}