项目作者: zurfyx

项目描述 :
Fetch with default absolute URLs.
高级语言: JavaScript
项目地址: git://github.com/zurfyx/fetch-absolute.git
创建时间: 2017-02-26T13:43:47Z
项目社区:https://github.com/zurfyx/fetch-absolute

开源协议:MIT License

下载


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

  1. npm install fetch-absolute

Usage

  1. var fetch = require('node-fetch');
  2. var fetchAbsolute = require('fetch-absolute');
  3. global.fetchApi = fetchAbsolute(fetch)('http://localhost:3030');

Example

Using node-fetch and fetch-absolute with Node 7 async/await:

  1. const fetch = require('node-fetch');
  2. const fetchAbsolute = require('fetch-absolute');
  3. const fetchApi = fetchAbsolute(fetch)('http://localhost:3030');
  4. it('should should display "It works!"', async () => {
  5. const response = await fetchApi('/');
  6. const json = await response.json();
  7. expect(json).to.eql({ msg: 'It works!' });
  8. });

Requested absolute URLs must start with /, otherwise they will be treated as relative.

License

MIT © Gerard Rovira Sánchez