superagent-absolute

1.0.1 • Public • Published

Superagent Absolute

Superagent with default absolute URLs.

Build Status npm version

Tired of writing http://localhost in front of every 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.

License

MIT © Gerard Rovira Sánchez

Package Sidebar

Install

npm i superagent-absolute

Weekly Downloads

107

Version

1.0.1

License

MIT

Last publish

Collaborators

  • zurfyx