fetch-absolute
v1.0.0
Published
Fetch with absolute URLs.
Downloads
2,523
Maintainers
Readme
Fetch Absolute
Fetch with default absolute URLs.
Tired of writing http://localhost
in front of every fetch request?
With fetch absolute you'll only write it once per host in your whole environment.
It works with both window.fetch and node-fetch.
Install
npm install fetch-absolute
Usage
var fetch = require('node-fetch');
var fetchAbsolute = require('fetch-absolute');
global.fetchApi = fetchAbsolute(fetch)('http://localhost:3030');
Example
Using node-fetch and fetch-absolute with Node 7 async/await:
const fetch = require('node-fetch');
const fetchAbsolute = require('fetch-absolute');
const fetchApi = fetchAbsolute(fetch)('http://localhost:3030');
it('should should display "It works!"', async () => {
const response = await fetchApi('/');
const json = await response.json();
expect(json).to.eql({ msg: 'It works!' });
});
Requested absolute URLs must start with /
, otherwise they will be treated as relative.
Related
- superagent-absolute - Superagent with default absolute URLs.
License
MIT © Gerard Rovira Sánchez