https://github.com/eyolas/superagent-interface-promise
fork superagent-es6-promise but use an interface for promise
https://github.com/eyolas/superagent-interface-promise
Last synced: 8 months ago
JSON representation
fork superagent-es6-promise but use an interface for promise
- Host: GitHub
- URL: https://github.com/eyolas/superagent-interface-promise
- Owner: eyolas
- License: mit
- Created: 2015-06-16T08:24:13.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-11-04T13:02:51.000Z (over 10 years ago)
- Last Synced: 2025-01-29T10:48:24.951Z (over 1 year ago)
- Language: JavaScript
- Size: 112 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/eyolas/superagent-interface-promise)
superagent-interface-promise
===========================
Add promise support to
[Superagent](http://visionmedia.github.io/superagent/).
it was initially forked from [superagent-bluebird-promise](https://github.com/KyleAMathews/superagent-bluebird-promise).
## Install
`npm install superagent-interface-promise`
## Usage
Simply require this package instead of `superagent`. Then you can call `.then()` instead of `.end()` to get a promise for your requests.
```javascript
var request = require('superagent-interface-promise');
request.get('/an-endpoint')
.then(function(res) {
console.log(res);
}, function(error) {
console.log(error);
});
```
To generate a promise without registering any callbacks (e.g. when returning a promise from within a library), call `.promise()` instead.
```javascript
request.get('/an-endpoint').promise()
```
An error is thrown for all HTTP errors and responses that have a response code of 400 or above.
The `error` parameter always has a key `error` and for 4xx and 5xx responses, will also have a `status` and `res` key.
## Promise
You can set the promise library
```javascript
var request = require('superagent-interface-promise');
var bluebird = require('bluebird');
request.Promise = bluebird;
```