Comparing version 0.4.1 to 0.5.0
@@ -20,6 +20,2 @@ 'use strict'; | ||
if (data && !reqOptions.headers['content-length']) { | ||
reqOptions.headers['content-length'] = data.length; | ||
} | ||
var deferred = defer(); | ||
@@ -26,0 +22,0 @@ |
@@ -13,3 +13,2 @@ 'use strict' | ||
* - Returns a promise, resolving to an object containing the data, node response and original request. | ||
* - If data was supplied, sets a `content-length` header if not already present. | ||
* - Automatically selects `http` or `https` transport depending on the input URL. | ||
@@ -24,6 +23,20 @@ * - Cancellable (which `fetch` is not). | ||
* .then(response => { | ||
* console.log('Response received', response.data) | ||
* console.log('Response data received', response.data) | ||
* console.log('The original request options', response.req) | ||
* console.log('The nodejs response instance', response.res) | ||
* }) | ||
* .catch(console.error) | ||
* @example | ||
* const request = require('req-then') | ||
* const url = require('url') | ||
* const reqOptions = url.parse('http://www.bbc.co.uk') | ||
* const controller = {} | ||
* reqOptions.controller = controller | ||
* request(reqOptions) | ||
* .then(response => { | ||
* console.log('Response data received', response.data) | ||
* }) | ||
* | ||
* // kill the request and close the socket | ||
* controller.abort() | ||
*/ | ||
@@ -50,6 +63,2 @@ module.exports = request | ||
if (data && !reqOptions.headers['content-length']) { | ||
reqOptions.headers['content-length'] = data.length | ||
} | ||
const deferred = defer() | ||
@@ -56,0 +65,0 @@ |
{ | ||
"name": "req-then", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Simple http(s) request function, returning a promise. ", | ||
@@ -36,8 +36,8 @@ "repository": "https://github.com/75lb/req-then", | ||
"lodash.pick": "^4.4.0", | ||
"typical": "^2.5.0" | ||
"typical": "^2.6.0" | ||
}, | ||
"devDependencies": { | ||
"babel-preset-es2015": "^6.13.2", | ||
"babel-preset-es2015": "^6.14.0", | ||
"jsdoc-to-markdown": "^2.0.0-alpha.11" | ||
} | ||
} |
@@ -12,3 +12,2 @@ [![view on npm](http://img.shields.io/npm/v/req-then.svg)](https://www.npmjs.org/package/req-then) | ||
- Returns a promise, resolving to an object containing the data, node response and original request. | ||
- If data was supplied, sets a `content-length` header if not already present. | ||
- Automatically selects `http` or `https` transport depending on the input URL. | ||
@@ -23,3 +22,4 @@ - Cancellable (which `fetch` is not). | ||
.then(response => { | ||
console.log('Response received', response.data) | ||
console.log('Response data received', response.data) | ||
console.log('The original request options', response.req) | ||
console.log('The nodejs response instance', response.res) | ||
@@ -29,2 +29,17 @@ }) | ||
``` | ||
**Example** | ||
```js | ||
const request = require('req-then') | ||
const url = require('url') | ||
const reqOptions = url.parse('http://www.bbc.co.uk') | ||
const controller = {} | ||
reqOptions.controller = controller | ||
request(reqOptions) | ||
.then(response => { | ||
console.log('Response data received', response.data) | ||
}) | ||
// kill the request and close the socket | ||
controller.abort() | ||
``` | ||
<a name="exp_module_req-then--request"></a> | ||
@@ -31,0 +46,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12237
216
61
Updatedtypical@^2.6.0