iuux / adrx-quicknotes

Quick Notes functionality for Indiana University AdRx (Advising Records) system.
MIT License
0 stars 0 forks source link

Create promise-like plugin for Superagent #34

Open basham opened 9 years ago

basham commented 9 years ago

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();
basham commented 9 years ago

Plugin exemplars

https://github.com/visionmedia/superagent#plugins https://github.com/johntron/superagent-no-cache/blob/master/index.js https://github.com/johntron/superagent-prefix/blob/master/index.js https://github.com/wheresrhys/superagent-promises/blob/master/index.js