prequest
Promisified HTTP requests with bluebird
and request
modules.
Grab it
$ npm install prequest
prequest usage
GET example
With this wrapper, we can easily make requests and catch any http failures in a promise's catch. By default, method is GET
:
var prequest = ; ;
If you need the full response (e.g. to view headers), specify arrayResponse: true
to have the response and body in an array. You may use bluebird's spread
to access the items directly:
console;);
POST example
All options supported by request
can be supplied to prequest.
By default, json: true
is enabled to set body payload as a JSON representation. If you do not want this, simply override it to false.
var prequest = ; console;);
To use the other methods: [delete, patch, head], specify it in method.
Testing
To run the tests:
$ npm install
$ npm test
The past, without prequest
Without this wrapper, a common pattern to promisify
requests:
var Promise = ;var prequest = Promise;
Contribute
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -m 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D