https://github.com/eccenca/ecc-superagent
Extended version of superagent.js with RX, better Link header parsing and HTTP Problem support
https://github.com/eccenca/ecc-superagent
Last synced: about 1 year ago
JSON representation
Extended version of superagent.js with RX, better Link header parsing and HTTP Problem support
- Host: GitHub
- URL: https://github.com/eccenca/ecc-superagent
- Owner: eccenca
- Created: 2018-01-23T08:34:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-09T13:48:20.000Z (about 8 years ago)
- Last Synced: 2024-04-14T11:51:09.561Z (about 2 years ago)
- Language: JavaScript
- Size: 209 KB
- Stars: 0
- Watchers: 14
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Eccenca extended Superagent lib (ecc-superagent)
Extended version of Superagent.js to use within eLDS framework
## Usage
Includes [Superagent.js](https://github.com/visionmedia/superagent) and [Superagent-rx](https://github.com/yamalight/superagent-rx) packages.
So, all you need to use it is import and call with your ajax requests:
```js
import request from 'ecc-superagent';
// ...
// parse results
request
.get(requestUrl)
.observe() // this returns Rx.Observable
.subscribe(function(res) {
// use res
});
// use results ...
```
Futhermore it is possible to register/unregister global superagent plugins to manipulate each request.
For Example:
```
import request from 'ecc-superagent';
// Register a plugin which sets a header on each request
request.useForEachRequest('setHeaderPlugin', (request) => {
request.set('X-Example-Header', 'FOO');
return request;
});
// The following request will have the X-Example-Header set
request
.get('http://example.org')
.observe() // this returns Rx.Observable
.subscribe(function(res) {
// use res
});
// Disable the plugin
request.useForEachRequest('setHeaderPlugin', false);
```