superagent-promise

Simple/dumb promise wrapper for superagent

  • Owner: lightsofapollo/superagent-promise
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Build Status

superagent-promise

Simple/dumb promise wrapper for superagent. You must depend on superagent and your favorite Promise library directly.

Usage

var Promise = this.Promise, require('promise');
var agent = require('superagent-promise')(require('superagent'), Promise);

// method, url form with `end`
agent('GET', 'http://google.com')
  .end()
  .then(function onResult(res) {
    // do stuff
  }, function onError(err) {
    //err.response has the response from the server
  });

// method, url form with `then`
agent('GET', 'http://google.com')
  .then(function onResult(res) {
    // do stuff
  });


// helper functions: options, head, get, post, put, patch, del
agent.put('http://myxfoo', 'data')
  .end()
  .then(function(res) {
    // do stuff`
  });

// helper functions: options, head, get, post, put, patch, del
agent.put('http://myxfoo', 'data').
  .then(function(res) {
    // do stuff
  });

Mocking

Now superagent-promise can be mocked using superagent-mock. For the complete example see
test/mock.spec.js and test/mock.config.js.

var SUCCESS_BODY = 'Yay! Mocked :)';
var mockedRequest = require('superagent');
var mocks = require('./mock.config')('localhost', SUCCESS_BODY);
require('superagent-mock')(mockedRequest, mocks);
var request = require('../index')(mockedRequest, Promise);

Main metrics

Overview
Name With Ownerlightsofapollo/superagent-promise
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 1)
Platform
License:MIT License
所有者活动
Created At2014-01-28 10:50:27
Pushed At2018-06-04 14:36:25
Last Commit At2018-06-04 07:36:24
Release Count7
Last Release Namev1.1.0 (Posted on 2015-12-22 17:38:25)
First Release Name0.1.0 (Posted on )
用户参与
Stargazers Count129
Watchers Count1
Fork Count27
Commits Count43
Has Issues Enabled
Issues Count14
Issue Open Count5
Pull Requests Count9
Pull Requests Open Count2
Pull Requests Close Count4
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private