{"name":"then-request","version":"1.0.4","description":"A request library that returns promises, inspired by request","keywords":[],"browser":"./browser.js","dependencies":{"promise":"^6.0.0","concat-stream":"^1.4.6","qs":"^2.2.3","http-response-object":"^1.0.1","http-basic":"^1.0.3"},"devDependencies":{"testit":"^1.2.0","istanbul":"^0.3.0"},"scripts":{"test":"node test/index.js && istanbul cover test/index.js"},"repository":{"type":"git","url":"https://github.com/then/request.git"},"author":{"name":"ForbesLindesay"},"license":"MIT","gitHead":"aa8abb6abf8929b98f685a13472b6043aeeec90d","bugs":{"url":"https://github.com/then/request/issues"},"homepage":"https://github.com/then/request","_id":"then-request@1.0.4","_shasum":"b49d4436e74777d756adb674d1dd80e201933cd5","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"forbeslindesay","email":"forbes@lindeay.co.uk"},"maintainers":[{"name":"forbeslindesay","email":"forbes@lindesay.co.uk"}],"dist":{"shasum":"b49d4436e74777d756adb674d1dd80e201933cd5","tarball":"http://registry-npm.ywwl.com/then-request/download/then-request-1.0.4.tgz","integrity":"sha512-L8ZBaOOOO79Xn6D0EZTMxBFhWjjvjBNKh3nmUk64UNBicxKHJy4AL+V9Q36HBiCTCK74eExGKRRaBZ7QHq2AFQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDINVQx7WEV0FC+e96sfFG/2/JQMtAiCdvlO8pw/lufQgIhAN0ewdzs4Mtu2t0pB5rxWkRSwJKRqTP2EipUC2vp3OSu"}],"size":5503,"noattachment":false,"key":"/then-request/-/then-request-1.0.4.tgz"},"directories":{},"readme":"# then-request\n\nA request library that returns promises and supports both browsers and node.js\n\n[![Build Status](https://img.shields.io/travis/then/then-request/master.svg)](https://travis-ci.org/then/then-request)\n[![Dependency Status](https://img.shields.io/david/then/then-request.svg)](https://david-dm.org/then/then-request)\n[![NPM version](https://img.shields.io/npm/v/then-request.svg)](https://www.npmjs.org/package/then-request)\n\n<a target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/gg9sZwctSLxyov1sJwW6pfyS/then/then-request'>\n  <img alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/gg9sZwctSLxyov1sJwW6pfyS/then/then-request.svg' />\n</a>\n\n## Installation\n\n    npm install then-request\n\n## Usage\n\n`request(method, url, options, callback?)`\n\nThe following examples all work on both client and server.\n\n```js\nvar request = require('then-request');\n\nrequest('GET', 'http://example.com').done(function (res) {\n  console.log(res.getBody());\n});\n\nrequest('POST', 'http://example.com/json-api', {json: {some: 'values'}}).getBody('utf8').then(JSON.parse).done(function (res) {\n  console.log(res);\n});\n\nvar FormData = request.FormData;\nvar data = new FormData();\n\ndata.append('some', 'values');\n\nrequest('POST', 'http://example.com/form-api', {form: data}).done(function (res) {\n  console.log(res.getBody());\n});\n```\n\nOr with ES6\n\n```js\nimport request, {FormData} from 'then-request';\n\nrequest('GET', 'http://example.com').done((res) => {\n  console.log(res.getBody());\n});\n\nrequest('POST', 'http://example.com/json-api', {json: {some: 'values'}}).getBody('utf8').then(JSON.parse).done((res) => {\n  console.log(res);\n});\n\nvar FormData = request.FormData;\nvar data = new FormData();\n\ndata.append('some', 'values');\n\nrequest('POST', 'http://example.com/form-api', {form: data}).done((res) => {\n  console.log(res.getBody());\n});\n```\n\n**Method:**\n\nAn HTTP method (e.g. `GET`, `POST`, `PUT`, `DELETE` or `HEAD`). It is not case sensitive.\n\n**URL:**\n\nA url as a string (e.g. `http://example.com`). Relative URLs are allowed in the browser.\n\n**Options:**\n\n - `qs` - an object containing querystring values to be appended to the uri\n - `headers` - http headers (default: `{}`)\n - `body` - body for PATCH, POST and PUT requests.  Must be a `Buffer`, `ReadableStream` or `String` (only strings are accepted client side)\n - `json` - sets `body` but to JSON representation of value and adds `Content-type: application/json`.  Does not have any affect on how the response is treated.\n - `form` - You can pass a `FormData` instance to the `form` option, this will manage all the appropriate headers for you.  Does not have any affect on how the response is treated.\n - `cache` - only used in node.js (browsers already have their own caches) Can be `'memory'`, `'file'` or your own custom implementaton (see https://github.com/ForbesLindesay/http-basic#implementing-a-cache).\n - `followRedirects` - defaults to `true` but can be explicitly set to `false` on node.js to prevent then-request following redirects automatically.\n - `maxRedirects` - sets the maximum number of redirects to follow before erroring on node.js (default: `Infinity`)\n - `allowRedirectHeaders` (default: `null`) - an array of headers allowed for redirects (none if `null`).\n - `gzip` - defaults to `true` but can be explicitly set to `false` on node.js to prevent then-request automatically supporting the gzip encoding on responses.\n - `agent` - (default: `false`) - An `Agent` to controll keep-alive. When set to `false` use an `Agent` with default values.\n - `timeout` (default: `false`) - times out if no response is returned within the given number of milliseconds.\n - `socketTimeout` (default: `false`) - calls `req.setTimeout` internally which causes the request to timeout if no new data is seen for the given number of milliseconds.  This option is ignored in the browser.\n - `retry` (default: `false`) - retry GET requests.  Set this to `true` to retry when the request errors or returns a status code greater than or equal to 400 (can also be a function that takes `(err, req, attemptNo) => shouldRetry`)\n - `retryDelay` (default: `200`) - the delay between retries (can also be set to a function that takes `(err, res, attemptNo) => delay`)\n - `maxRetries` (default: `5`) - the number of times to retry before giving up.\n\n\n**Returns:**\n\nA [Promise](https://www.promisejs.org/) is returned that eventually resolves to the `Response`.  The resulting Promise also has an additional `.getBody(encoding?)` method that is equivallent to calling `.then(function (res) { return res.getBody(encoding?); })`.\n\n### Response\n\nNote that even for status codes that represent an error, the promise will be resolved as the request succeeded.  You can call `getBody` if you want to error on invalid status codes.  The response has the following properties:\n\n - `statusCode` - a number representing the HTTP status code\n - `headers` - http response headers\n - `body` - a string if in the browser or a buffer if on the server\n - `url` - the URL that was requested (in the case of redirects on the server, this is the final url that was requested)\n\nIt also has a method `getBody(encoding?)` which looks like:\n\n```js\nfunction getBody(encoding) {\n  if (this.statusCode >= 300) {\n    var err = new Error('Server responded with status code ' + this.statusCode + ':\\n' + this.body.toString(encoding));\n    err.statusCode = this.statusCode;\n    err.headers = this.headers;\n    err.body = this.body;\n    throw err;\n  }\n  return encoding ? this.body.toString(encoding) : this.body;\n}\n```\n\n### FormData\n\n```js\nvar FormData = require('then-request').FormData;\n```\n\nForm data either exposes the node.js module, [form-data](https://www.npmjs.com/package/form-data), or the builtin browser object [FormData](https://developer.mozilla.org/en/docs/Web/API/FormData), as appropriate.\n\nThey have broadly the same API, with the exception that form-data handles node.js streams and Buffers, while FormData handles the browser's `File` Objects.\n\n## License\n\n  MIT\n","publish_time":1411997187776,"_cnpm_publish_time":1411997187776,"dist-tags":{"latest":"6.0.2"}}