{"bugs":{"url":"https://github.com/blakeembrey/popsicle/issues"},"dist":{"shasum":"2abd36130560647c74eaf08400d473ae25c4486f","tarball":"https://registry.npmjs.org/popsicle/-/popsicle-10.0.1.tgz","fileCount":58,"integrity":"sha512-IFVBRz+hc05+MiVDH+KH9QoeE6gjFOiIZNxKePIwz+JbH/yP9rLreUT9+GocxRweYBiRh7O9+MfI5X1zKfSH6Q==","signatures":[{"sig":"MEUCIQDg37RnOi8bZOeJtsLqx11gME1/mNKSCjT0CeE1rONECQIgIwyy6oqi1pAWo4sPYyqPc1n0R5XGWDRutFBjdEb+HIM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":239609,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbBPshCRA9TVsSAnZWagAAaTgP+wXlMlv202RpzRqEShza\nqvdXnSJiyNnJZMqzNR8cYtYTN63o3ODL0ib0YA2ccINfz6nwawCUZ6R151Jc\nP7I02FZuGO94wRXLfWVr4w8DqQokJn2RKDPCvxWeIyzexpRRUOWUuuJpbOHf\nCO8ALWxhvT31qVVaqF5IXASIA9eWHRIEXfMr/8gENDzkz8hRawYSUn8Inwj0\nogNGDHolA8DobzqKEJmz8hQYvzUoHDmG5cvt0Ee+dzbTcZMCBH9LssBfcFN9\nsJ7ycsLt3Jp4Fk1ax94Y2DD/qQwi02NqHkYH90A/F2et2w+o6U0GwOkChKFp\neBHKc+aOT1JyxDdt/u3cVeTUU04006PxJBL0DwU/cnYBNahLkFLDA2eq8hA2\nst8dzq59wCBDAb9rg4E2QWbM7Gt000hWoBcs7h98kshIJOhS7tIl08hmNJqV\nq7tNtm6gNgCKwWNWnID4hcSS9i1yc8XQv8TtvbHTkWPxz8d1btzvvZGU86nd\ndhZk23UYrjTxmk9pLFVlN3MX1ETGZZR+vDPmFM3+3TAyGoG/Wcu7Na2RmQiY\neAO5f5nIjRb5zaNXlD0bR8ppJ51NDuyVB+3WHpp5no18KG3MOO4jHLV/1bql\nD9NeVLhkBI764GQrLei3fTYFhAAo5O45nLJ4AxZdQ2Ev0M9tK9+SepReIEtx\nlZzN\r\n=c/S4\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/common.js","name":"popsicle","files":["dist/","LICENSE","logo.svg"],"types":"dist/common.d.ts","author":{"url":"http://blakeembrey.me","name":"Blake Embrey","email":"hello@blakeembrey.com"},"readme":"# ![Popsicle](https://cdn.rawgit.com/blakeembrey/popsicle/master/logo.svg)\n\n[![NPM version](https://img.shields.io/npm/v/popsicle.svg?style=flat)](https://npmjs.org/package/popsicle)\n[![NPM downloads](https://img.shields.io/npm/dm/popsicle.svg?style=flat)](https://npmjs.org/package/popsicle)\n[![Build status](https://img.shields.io/travis/blakeembrey/popsicle.svg?style=flat)](https://travis-ci.org/blakeembrey/popsicle)\n[![Test coverage](https://img.shields.io/coveralls/blakeembrey/popsicle.svg?style=flat)](https://coveralls.io/r/blakeembrey/popsicle?branch=master)\n[![Greenkeeper badge](https://badges.greenkeeper.io/blakeembrey/popsicle.svg)](https://greenkeeper.io/)\n\n> **Popsicle** is the easiest way to make HTTP requests - a consistent, intuitive and tiny API that works on node and the browser. 9.37 kB in browsers, after minification and gzipping, including dependencies (with `url` being the bulk of it).\n\n```js\npopsicle.get('/users.json')\n  .then(function (res) {\n    console.log(res.status) //=> 200\n    console.log(res.body) //=> { ... }\n    console.log(res.headers) //=> { ... }\n  })\n```\n\n## Installation\n\n```\nnpm install popsicle --save\n```\n\n## Usage\n\n```js\nconst popsicle = require('popsicle')\n\npopsicle.request({\n  method: 'POST',\n  url: 'http://example.com/api/users',\n  body: {\n    username: 'blakeembrey',\n    password: 'hunter2'\n  },\n  headers: {\n    'Content-Type': 'application/x-www-form-urlencoded'\n  }\n})\n  .use(popsicle.plugins.parse('json'))\n  .then(function (res) {\n    console.log(res.status) // => 200\n    console.log(res.body) //=> { ... }\n    console.log(res.get('Content-Type')) //=> 'application/json'\n  })\n```\n\n**Popsicle** is a promise-based HTTP request library designed for extensibility. Here's the functions you can import from `popsicle`:\n\n* **request(options)** The default request handler (also `get`)\n* **defaults(options)** Create a new Popsicle instance with `defaults`\n* **form(obj?)** Cross-platform form data object\n* **plugins** Exposes the default plugins (Object)\n* **jar(store?)** Create a cookie jar instance for Node.js\n* **transport** Default transportation layer (Object)\n* **Request(options)** Constructor for the `Request` class\n* **Response(options)** Constructor for the `Response` class\n\n### Request Options\n\n* **url** _(string)_ The resource location.\n* **method** _(string)_ The HTTP request method (default: `\"GET\"`).\n* **headers** _(object)_ A map of header key to value (default: `{}`).\n* **query** _(object | string)_ A map or string to be appended to the URL as the query string.\n* **body** _(any)_ An object, string, form data, stream (node) or other to pass with the request.\n* **timeout** _(number)_ The number of milliseconds to wait before aborting the request (default: `Infinity`)\n* **use** _(array)_ An array of plugins to override the defaults (default: `[stringify(), headers()]`)\n* **transport** _(object)_ Set the transport layer (default: `createTransport({ type: 'text' })`)\n\n### Built-in Plugins\n\n#### `stringify` (default)\n\nAutomatically serialize the request body into a string (E.g. JSON, URL-encoded or multipart).\n\n#### `headers` (default)\n\nSets up default headers for environments. For example, `Content-Length`, `User-Agent`, `Accept`, etc.\n\n#### `parse`\n\nAutomatically parses allowed response type(s).\n\n* **json** Parse response as JSON\n* **urlencoded** Parse response as URL-encoded\n\n```js\npopsicle.get('/users')\n  .use(popsicle.plugins.parse(['json', 'urlencoded']))\n  .then(() => ...)\n```\n\n### Built-in Transports\n\nPopsicle provides two transports, one for node (using `{http,https}.request`) and one for browsers (using `XMLHttpRequest`). These transports have a number of \"types\" built-in for handling the response body.\n\n* **text** Handle response as a string (default)\n* **document** `responseType === 'document'` (browsers)\n* **blob** `responseType === 'blob'` (browsers)\n* **arraybuffer** `responseType === 'arraybuffer'` (browsers)\n* **buffer** Handle response as a buffer (node.js)\n* **array** Handle response as an array of integers (node.js)\n* **uint8array** Handle the response as a `Uint8Array` (node.js)\n* **stream** Respond with the response body stream (node.js)\n\n**Node transport options**\n\n* **type** Handle the response (default: `text`)\n* **unzip** Automatically unzip response bodies (default: `true`)\n* **jar** An instance of a cookie jar (`popsicle.jar()`) (default: `null`)\n* **agent** Custom HTTP pooling agent\n* **maxRedirects** Override the number of redirects allowed (default: `5`)\n* **maxBufferSize** The maximum size of the buffered response body (default: `2000000`)\n* **rejectUnauthorized** Reject invalid SSL certificates (default: `true`)\n* **confirmRedirect** Confirm redirects on `307` and `308` status codes (default: `() => false`)\n* **ca** A string, `Buffer` or array of strings or `Buffers` of trusted certificates in PEM format\n* **key** Private key to use for SSL (default: `null`)\n* **cert** Public x509 certificate to use (default: `null`)\n\n**Browser transport options**\n\n* **type** Handle the XHR response (default: `text`)\n* **withCredentials** Send cookies with CORS requests (default: `false`)\n* **overrideMimeType** Override the XHR response MIME type\n\n### Short-hand Methods\n\nCommon methods have a short hand exported (created using `defaults({ method })`).\n\n```js\npopsicle.get('http://example.com/api/users')\npopsicle.post('http://example.com/api/users')\npopsicle.put('http://example.com/api/users')\npopsicle.patch('http://example.com/api/users')\npopsicle.del('http://example.com/api/users')\n```\n\n### Default Instances\n\nCreate a new Popsicle instance with defaults pre-populated. Handy for a common cookie jar or transport to be used.\n\n```js\nconst cookiePopsicle = popsicle.defaults({\n  transport: popsicle.createTransport({\n    jar: popsicle.jar()\n  })\n})\n```\n\n### Automatically Stringify Request Body\n\nPopsicle will automatically serialize the request body using the `stringify` plugin. If an object is supplied, it will automatically be stringified as JSON unless the `Content-Type` was set otherwise. If the `Content-Type` is `application/json`, `multipart/form-data` or `application/x-www-form-urlencoded`, it will be automatically serialized accordingly.\n\n```js\npopsicle.get({\n  url: 'http://example.com/api/users',\n  body: {\n    username: 'blakeembrey'\n  },\n  headers: {\n    'Content-Type': 'application/x-www-form-urlencoded'\n  }\n})\n```\n\n### Multipart Request Bodies\n\nYou can manually create a `FormData` instance by calling `popsicle.form`. When you pass a form data instance as the body, it'll automatically set the correct `Content-Type` - complete with boundary.\n\n```js\nconst form = popsicle.form({\n  username: 'blakeembrey',\n  profileImage: fs.createReadStream('image.png')\n})\n\nform.append('x', 'y')\n\npopsicle.post({\n  url: '/users',\n  body: form\n})\n```\n\n### Cookie Jar (Node only)\n\nYou can create a reusable cookie jar instance for requests by calling `popsicle.jar`.\n\n```js\nconst jar = popsicle.jar()\n\npopsicle.request({\n  method: 'post',\n  url: '/users',\n  transport: popsicle.createTransport({\n    jar: jar\n  })\n})\n```\n\n### Request Class\n\nCalling any of the request functions will return an instance of `Request`.\n\n* **method** _(string)_ The request method.\n* **timeout** _(number)_ Configured request timeout.\n* **body** _(any)_ The request payload.\n* **transport** _(object)_ The transportation layer.\n* **events** _(object)_ A map of configured event listeners.\n* **middleware** _(array)_ The list of configured middleware.\n* **opened** _(boolean)_ A flag indicating the transport was started.\n* **aborted** _(boolean)_ A flag indicating the request was aborted before finishing.\n* **uploaded** _(number)_ The percentage of upload complete (between 0 and 1).\n* **downloaded** _(number)_ The percentage of download complete (between 0 and 1).\n* **uploadedBytes** (number)_ Number of bytes uploaded.\n* **downloadedBytes** _(number)_ Number of bytes downloaded.\n* **uploadLength** _(number)_ Known size of total upload bytes.\n* **downloadLength** _(number)_ Known size of total download bytes.\n* **error(message, code, original?)** Create a `PopsicleError` instance.\n* **then(onFulfilled?, onRejected?)** Promise interface.\n* **catch(onRejected)** Promise interface.\n* **exec(cb)** Callback interface.\n* **toOptions()** Return a new object representing the request options.\n* **toJSON()** A JSON friendly representation of the request.\n* **clone()** Return a new instance of `Request` from `toOptions()`.\n* **use(middleware)** Append middleware to the current request.\n* **on(event, fn)** Attach an event listener.\n* **off(event, fn)** Detach an event listener.\n* **once(event, fn)** Attach an event listener that automatically detaches after the first execution.\n* **emit(event, ...args)** Emit an event (mostly internal use).\n* **abort()** Abort the current request by emitting the `abort` event.\n\n**P.S.** When cloning a request instance, the current middleware and events are copied. This allows event tricks like `abort()` to also abort cloned request instances (e.g. in the case where working with request retries, and aborting should still work on re-attempts).\n\n#### Promises\n\nPromises are the most expressive interface. Just chain using `Request#then` or `Request#catch` and continue.\n\n```js\npopsicle.get('/users')\n  .then(function (res) {\n    // Success!\n  })\n  .catch(function (err) {\n    // Something broke.\n  })\n```\n\nIf you live on the edge, try with generators ([co](https://www.npmjs.com/package/co)) or ES7 `async`/`await`.\n\n```js\nco(function * () {\n  const users = yield popsicle.get('/users')\n})\n\nasync function () {\n  const users = await popsicle.get('/users')\n}\n```\n\n#### Callbacks\n\nFor tooling that expects node-style callbacks, you can use `Request#exec`. This accepts a single function to call when the response is complete.\n\n```js\npopsicle.get('/users')\n  .exec(function (err, res) {\n    if (err) {\n      // Something broke.\n    }\n\n    // Success!\n  })\n```\n\n### Aborting\n\nAll requests can be aborted before or during execution by calling `Request#abort`.\n\n```js\nconst request = popsicle.get('http://example.com')\n\nsetTimeout(function () {\n  request.abort()\n}, 100)\n\nrequest.catch(function (err) {\n  console.log(err) //=> { message: 'Request aborted', code: 'EABORTED' }\n})\n```\n\n#### Progress\n\nThe request object can be used to check progress at any time.\n\n* **request.uploadedBytes** Current upload size in bytes\n* **request.uploadLength** Total upload size in bytes\n* **request.uploaded** Total uploaded as a percentage\n* **request.downloadedBytes** Current download size in bytes\n* **request.downloadLength** Total download size in bytes\n* **request.downloaded** Total downloaded as a percentage\n* **request.completed** Total uploaded and downloaded as a percentage\n\nAll percentage properties (`request.uploaded`, `request.downloaded`, `request.completed`) are a number between `0` and `1`. Aborting the request will emit a progress event, if the request had started.\n\n```js\nconst request = popsicle.get('http://example.com')\n\nrequest.uploaded //=> 0\nrequest.downloaded //=> 0\n\nrequest.on('progress', function () {\n  console.log(request) //=> { uploaded: 1, downloaded: 0, completed: 0.5, aborted: false }\n})\n\nrequest.then(function (response) {\n  console.log(request.downloaded) //=> 1\n})\n```\n\n#### Errors\n\nAll response methods can return an error. Errors have a `popsicle` property set to the request object and a `code` string. The built-in codes are documented below, but custom errors can be created using `request.error(message, code, cause)`.\n\n* **EABORT** Request has been aborted by user\n* **EUNAVAILABLE** Unable to connect to the remote URL\n* **EINVALID** Request URL is invalid\n* **ETIMEOUT** Request has exceeded the allowed timeout\n* **ESTRINGIFY** Request body threw an error during stringification plugin\n* **EPARSE** Response body threw an error during parse\n* **EMAXREDIRECTS** Maximum number of redirects exceeded (Node only)\n* **EBODY** Unable to handle request body (Node only)\n* **EBLOCKED** The request was blocked (HTTPS -> HTTP) (Browsers only)\n* **ECSP** Request violates the documents Content Security Policy (Browsers only)\n* **ETYPE** Invalid transport type\n\n### Response Class\n\nEvery response will give a `Response` instance on success. T\n\n* **status** The HTTP response status code\n* **body** The response body from the transport layer (usually text or a stream)\n* **headers** An object of lower-cased keys to header values\n* **url** The final response URL (after redirects)\n* **statusType()** Return an integer with the HTTP status type (E.g. `200 -> 2`)\n* **get(key)** Retrieve a HTTP header using a case-insensitive key\n* **name(key)** Retrieve the original HTTP header name using a case-insensitive key\n* **type()** Return the response type (E.g. `application/json`)\n\n### Plugins\n\nPlugins can be set as an array with the initial options (which overrides default plugins), or they can be used via `Request#use`.\n\n#### External Plugins\n\n* [Server](https://github.com/blakeembrey/popsicle-server) - Automatically mount a server on an available for the request (helpful for testing a la `supertest`)\n* [Status](https://github.com/blakeembrey/popsicle-status) - Reject responses on HTTP failure status codes\n* [No Cache](https://github.com/blakeembrey/popsicle-no-cache) - Prevent caching of HTTP requests in browsers\n* [Basic Auth](https://github.com/blakeembrey/popsicle-basic-auth) - Add a basic authentication header to each request\n* [Prefix](https://github.com/blakeembrey/popsicle-prefix) - Prefix all HTTP requests\n* [Resolve](https://github.com/blakeembrey/popsicle-resolve) - Resolve all HTTP requests against a base URL\n* [Limit](https://github.com/blakeembrey/popsicle-limit) - Transparently handle API rate limits by grouping requests\n* [Group](https://github.com/blakeembrey/popsicle-group) - Group requests and perform operations on them all at once\n* [Proxy Agent](https://github.com/blakeembrey/popsicle-proxy-agent) - Enable HTTP(s) proxying under node (with environment variable support)\n* [Retry](https://github.com/blakeembrey/popsicle-retry) - Retry a HTTP request on network error or server error\n* [Rewrite](https://github.com/lbovet/popsicle-rewrite) - Rewrite request URLs dynamically\n* [Cache](https://github.com/blakeembrey/popsicle-cache) - Enable caching for HTTP requests into a store (E.g. filesystem)\n\n#### Helpful Utilities\n\n* [`throat`](https://github.com/ForbesLindesay/throat) - Throttle promise-based functions with concurrency support\n* [`is-browser`](https://github.com/ForbesLindesay/is-browser) - Check if your in a browser environment (E.g. Browserify, Webpack)\n* [`parse-link-header`](https://github.com/thlorenz/parse-link-header) - Handy for parsing HTTP link headers\n\n#### Creating Plugins\n\nPlugins must be a function that accept config and return a middleware function. For example, here's a basic URL prefix plugin.\n\n```js\nfunction prefix (url) {\n  return function (self, next) {\n    self.url = url + self.url\n    return next()\n  }\n}\n\npopsicle.request('/user')\n  .use(prefix('http://example.com'))\n  .then(function (response) {\n    console.log(response.url) //=> \"http://example.com/user\"\n  })\n```\n\nMiddleware functions accept two arguments - the current request and a function to proceed to the next middleware function (a la Koa `2.x`).\n\n**P.S.** The middleware array is exposed on `request.middleware`, which allows you to clone requests and tweak middleware - for example, using `request.middleware.slice(request.middleware.indexOf(currentFn))`. This is useful, as the pre and post steps of previous middleware attach before `currentFn` is executed.\n\n### Transportation Layers\n\nCreating a custom transportation layer is just a matter creating an object with `open`, `abort` and `use` options set. The open method should set any request information required between called as `request._raw`. Abort must abort the current request instance, while `open` must **always** resolve to a promise. You can set `use` to an empty array if no plugins should be used by default. However, it's recommended you keep `use` set to the defaults, or as close as possible using your transport layer.\n\n## JavaScript\n\nThis module is designed for ES5 environments, but requires two ES2015 polyfills to work:\n\n1. `Promise` - `popsicle` is designed heavily with promises in mind\n2. `Object.assign` - used internally for object cloning\n\n## TypeScript\n\nThis project is written using [TypeScript](https://github.com/Microsoft/TypeScript) and publishes the typings to NPM alongside the package.\n\n## Development\n\nInstall dependencies and run the test runners (node and Electron using Tape).\n\n```\nnpm install && npm test\n```\n\n## Related Projects\n\n* [Superagent](https://github.com/visionmedia/superagent) - HTTP requests for node and browsers\n* [Fetch](https://github.com/github/fetch) - Browser polyfill for promise-based HTTP requests\n* [Axios](https://github.com/mzabriskie/axios) - HTTP request API based on Angular's $http service\n\n## License\n\nMIT\n","browser":{"buffer":false,"form-data":"./dist/browser/form-data.js","tough-cookie":"./dist/browser/tough-cookie.js","./dist/index.js":"./dist/browser.js","./dist/plugins/index.js":"./dist/plugins/browser.js","./dist/plugins/is-host/index.js":"./dist/plugins/is-host/browser.js"},"gitHead":"b46b59793ea5c7c0694f53b3394d1c680dde5781","license":"MIT","scripts":{"lint":"tslint \"src/**/*.ts\" --project tsconfig.json --type-check","test":"npm run lint && npm run build && npm run test-server-open && npm run test-cov && npm run test-browser; EXIT=$?; npm run test-server-close; exit $EXIT","build":"rm -rf dist/ && tsc && npm run check-size","test-cov":"HTTPS_PORT=7358 PORT=7357 istanbul cover --print none dist/test/index.js | tap-spec","test-spec":"npm run test-server-open && HTTPS_PORT=7358 PORT=7357 node dist/test/index.js; EXIT=$?; npm run test-server-close; exit $EXIT","check-size":"browserify . -s popsicle --external bluebird > popsicle.js && du -h popsicle.js","prepublish":"npm run build","test-browser":"HTTPS_PORT=7358 PORT=7357 browserify -d -t envify dist/test/index.js | tape-run --render tap-spec","test-server-open":"PORT=7357 node scripts/server.js & echo $! > server.pid; HTTPS_PORT=7358 node scripts/https-server.js & echo $! > https-server.pid","test-server-close":"if [ -f server.pid ]; then kill -9 $(cat server.pid); rm server.pid; fi; if [ -f https-server.pid ]; then kill -9 $(cat https-server.pid); rm https-server.pid; fi"},"_npmUser":{"name":"blakeembrey","email":"hello@blakeembrey.com"},"homepage":"https://github.com/blakeembrey/popsicle","keywords":["request","ajax","http","node","browser","promise","agent"],"repository":{"url":"git://github.com/blakeembrey/popsicle.git","type":"git"},"_npmVersion":"5.6.0","description":"Simple HTTP requests for node and the browser","directories":{},"maintainers":[{"name":"blakeembrey","email":"hello@blakeembrey.com"}],"_nodeVersion":"10.1.0","dependencies":{"form-data":"^2.0.0","tough-cookie":"^2.0.0","concat-stream":"^1.4.7","@types/methods":"^1.1.0","@types/form-data":"0.0.33","make-error-cause":"^1.2.1","@types/tough-cookie":"^2.3.0","@types/concat-stream":"^1.6.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"envify":"^4.0.0","tslint":"^5.2.0","express":"^4.10.2","methods":"^1.1.2","bluebird":"^3.0.5","istanbul":"^0.4.0","tap-spec":"^4.1.1","tape-run":"3.0.0","blue-tape":"^1.0.0","browserify":"^14.3.0","typescript":"^2.4.1","@types/node":"^8.0.0","body-parser":"^1.9.2","@types/blue-tape":"^0.1.30","tslint-config-standard":"^7.0.0"},"_npmOperationalInternal":{"tmp":"tmp/popsicle_10.0.1_1527053088677_0.29988236113853906","host":"s3://npm-registry-packages"},"_id":"popsicle@10.0.1","version":"10.0.1"}