Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create promise-like plugin for Superagent #34

Open
basham opened this issue Feb 23, 2015 · 1 comment
Open

Create promise-like plugin for Superagent #34

basham opened this issue Feb 23, 2015 · 1 comment

Comments

@basham
Copy link
Member

basham commented Feb 23, 2015

Extend request object, so you can change this code:

var request = require('superagent');

request
  .post(api)
  .end(function(res, err) {
    if(err || !res.ok) {
      // error
      return;
    }
    // success
  });

To this:

var request = require('superagent');
var requestPromise = require('superagent-promise');

request
  .use(requestPromise)
  .post(api)
  .then(function(value) {
    // success
  })
  .catch(function(err) {
    // error
  })
  .done();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant