https://github.com/zurfyx/superagent-absolute
Superagent with default absolute URLs.
https://github.com/zurfyx/superagent-absolute
absolute superagent url
Last synced: 2 months ago
JSON representation
Superagent with default absolute URLs.
- Host: GitHub
- URL: https://github.com/zurfyx/superagent-absolute
- Owner: zurfyx
- License: mit
- Created: 2017-02-25T20:36:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-26T13:43:04.000Z (over 8 years ago)
- Last Synced: 2025-03-29T15:11:54.205Z (7 months ago)
- Topics: absolute, superagent, url
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Superagent Absolute
> Superagent with default absolute URLs.
[](https://travis-ci.org/zurfyx/superagent-absolute)
[](https://badge.fury.io/js/superagent-absolute)Tired of writing `http://localhost` in front of every [superagent](https://github.com/visionmedia/superagent) request?
With superagent absolute you'll only write it once per host in your whole environment.## Install
```
npm install superagent-absolute
```## Usage
```
var superagent = require('superagent');
var superagentAbsolute = require('superagent-absolute');var agent = superagent.agent();
global.request = superagentAbsolute(agent)('http://localhost:3030');
```## Example
```
const superagent = require('superagent');
const superagentAbsolute = require('superagent-absolute');const agent = superagent.agent();
const request = superagentAbsolute(agent)('http://localhost:3030');it('should should display "It works!"', (done) => {
request
.get('/')
.end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body).to.eql({ msg: 'It works!' });
done();
});
});
```Requested absolute URLs must start with `/`, otherwise they will be treated as relative.
## Related
- [fetch-absolute](https://github.com/zurfyx/fetch-absolute) - Fetch with default absolute URLs.
## License
MIT © [Gerard Rovira Sánchez](//zurfyx.com)