The world-famous HTTP client "Request" now Promises/A+ compliant. Powered by Bluebird.
[Bluebird](https://github.com/petkaantonov/bluebird) and
[Request](https://github.com/mikeal/request) are pretty awesome, but I found
myself using the same design pattern. This is a simple wrapper that takes in a
request options object (or URI string), and returns a chainable promise. By
default, http response codes other than 2xx will cause the promise to
be rejected. This can be over-ridden by setting `options.simple` to `false`.
[Bluebird](https://github.com/petkaantonov/bluebird) and [Request](https://github.com/mikeal/request) are pretty awesome, but I found myself using the same design pattern. Request-Promise adds a `then` method to the Request object which returns a Bluebird promise for chainability. By default, http response codes other than 2xx will cause the promise to be rejected. This can be over-ridden by setting `options.simple` to `false`.
Note: As of version 0.1, `reject` now passes an object containing the following:
```js
reject({
error:body,
options:c,
response:response,
statusCode:response.statusCode
});
```
## Request-Promise is a drop-in replacement for Request
Since version 0.3.0 Request-Promise is not a wrapper around Request anymore. It now adds a `then` method to Request and exports the original Request object. This means you can now use all features of Request.
See the [migration instructions](#migrating-from-02x-to-03x) for important changes.
Request-Promise depends on loosely defined versions of Request and Bluebird. If you want to use specific versions of those modules please install them beforehand.
// transform is called just before promise is fulfilled
//displays length of response from server after post
// --> Displays length of response from server after post
// get full response after DELETE
// Get full response after DELETE
options={
method:'DELETE',
uri:'http://my-server/path/to/resource/1234',
resolveWithFullResponse:true
};
rp(options)
.then(function (response){
console.log("DELETE succeeded with status %d",response.statusCode);
@@ -70,13 +70,21 @@ rp(options)
.catch(console.error);
```
## API in detail
Description forthcoming.
## Debugging
The ways to debug the operation of `request-promise` are the same [as described](https://github.com/request/request#debugging) for `request`. However, there are small differences:
The ways to debug the operation of Request-Promise are the same [as described](https://github.com/request/request#debugging) for Request. These are:
1. Launch the node process like `NODE_DEBUG=request node script.js` (`lib,request,otherlib` works too).
2. Set `require('request-promise').request.debug = true` at any time (this does the same thing as #1).
3. Use the [request-debug module](https://github.com/nylen/request-debug) to view request and response headers and bodies. Instrument `request-promise` with `require('request-debug')(rp.request);`.
2. Set `require('request-promise').debug = true` at any time (this does the same thing as #1).
3. Use the [request-debug module](https://github.com/nylen/request-debug) to view request and response headers and bodies. Instrument Request-Promise with `require('request-debug')(rp);`.
## Migrating from 0.2.x to 0.3.x
Description forthcoming.
## Contributing
@@ -92,4 +100,11 @@ To set up your development environment:
If you want to debug a test you should use `gulp test-without-coverage` to run all tests without obscuring the code by the test coverage instrumentation.
## MIT Licenced
## Change History
- v0.3.0 (forthcoming)
- Carefully rewritten from scratch to make Request-Promise a [drop-in replacement for Request](#request-promise-is-a-drop-in-replacement-for-request)