Need help with superagent-promise?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

lightsofapollo
126 Stars 27 Forks MIT License 43 Commits 7 Opened issues

Description

Simple/dumb promise wrapper for superagent

Services available

!
?

Need anything else?

Contributors list

# 81,127
graphql...
js
lambda
serverl...
10 commits
# 71,193
screens...
osx
Objecti...
notes-a...
9 commits
# 98,207
Dart
gRPC
Flutter
Vue.js
3 commits
# 3,197
React N...
wechat-...
js
Koa
2 commits
# 67,623
npm
CSS
PHP
editorc...
1 commit
# 722,394
JavaScr...
1 commit

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);

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.