superagent-as-promised

4.0.0 • Public • Published

SuperAgent as Promise(d)

SuperAgent as Promise

Installation

npm install superagent-as-promised

Usage

var request = require('superagent');
require('superagent-as-promised')(request);

Then

request
.get('/location')
.then( function(response) {
  console.log("Got "+response.text);
})
.catch( function(error) {
  console.dir(error);
})

is syntactic sugar for:

var promise = request
  .get('/location')
  .endAsync();

promise
  .then( function(response) {
    console.log("Got "+response.text);
  })
  .catch( function(error) {
    console.dir(error);
  })

Options

require('superagent-as-promised')(SuperAgent,Promise);

SuperAgent must be a SuperAgent class; it is extended with endAsync(), then, and catch methods. The optional Promise parameter allows you to provide your own Promise class; bluebird is used by default.

Dependents (17)

Package Sidebar

Install

npm i superagent-as-promised

Weekly Downloads

1,635

Version

4.0.0

License

MIT

Last publish

Collaborators

  • shimaore