fetch-absolute

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i fetch-absolute

Weekly Downloads

305

Version

1.0.0

License

MIT

Last publish

Collaborators

  • zurfyx