fetch-absolute

Fetch with absolute URLs.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
fetch-absolute
101.0.06 years ago6 years agoMinified + gzip package size for fetch-absolute in KB

Readme

Fetch Absolute
Fetch with default absolute URLs.

Build Status npm version
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

License

MIT © Gerard Rovira Sánchez