How to use whatwg-fetch - 10 common examples

To help you get started, we’ve selected a few whatwg-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github electrode-io / electrode-native / system-tests-fixtures / ios-container / ElectrodeContainer / Libraries / ReactNative / Network / fetch.js View on Github external
*
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @providesModule fetch
 *
 */

 /* globals Headers, Request, Response */

'use strict';

import whatwg from 'whatwg-fetch';

if (whatwg && whatwg.fetch) {
  module.exports = whatwg;
} else {
  module.exports = {fetch, Headers, Request, Response};
}
github apache / incubator-echarts-doc / src / docHelper.js View on Github external
function ensurePageDescStorage(targetPath) {
    if (!pageOutlines) {
        throw new Error('Outline data is not loaded.');
    }
    let pagePath = targetPath.split('.')[0];

    // Configuration like `option.color`, `option.backgroundColor` is in the `option` page.
    // Configuration like `option.series-bar` is in the `option.series-bar` page.
    let partionKey = !pageOutlines[pagePath] || !targetPath
        ? rootName
        : rootName + '.' + pagePath;

    if (!descStorage[partionKey]) {
        let url = `${baseUrl}/${partionKey}.json?${docVersion}`;
        let fetcher = fetch(url).then(response => response.json());
        descStorage[partionKey] = {
            fetcher
        };

        fetcher.then(map => {
            descStorage[partionKey].indexer = createIndexer(map, pagePath);
        });
    }

    return descStorage[partionKey];
}
/**
github berty / berty / client / react-native / common / registerServiceWorker.js View on Github external
function checkValidServiceWorker (swUrl) {
  // Check if the service worker can be found. If it can't reload the page.
  fetch(swUrl)
    .then(response => {
      // Ensure service worker exists, and that we really are getting a JS file.
      if (
        response.status === 404 ||
        response.headers.get('content-type').indexOf('javascript') === -1
      ) {
        // No service worker found. Probably a different app. Reload the page.
        navigator.serviceWorker.ready.then(registration => {
          registration.unregister().then(() => {
            window.location.reload()
          })
        })
      } else {
        // Service worker found. Proceed as normal.
        registerValidSW(swUrl)
      }
github orangeloops / public-ol-native-template / config / jest / setup.js View on Github external
// Ensure environment variables are read.

const path = require("path");
const fs = require("fs-extra");
const dotenv = require("dotenv");

process.env = {
  ...process.env,
  ...dotenv.parse(fs.readFileSync(path.resolve(process.cwd(), ".env"))),
};

const fetchPolyfill = require("whatwg-fetch");

global.fetch = fetchPolyfill.fetch;
global.Request = fetchPolyfill.Request;
global.Headers = fetchPolyfill.Headers;
global.Response = fetchPolyfill.Response;

const axios = require("axios");
const httpAdapter = require("axios/lib/adapters/http");

axios.defaults.adapter = httpAdapter;

require("moment-timezone");
jest.doMock("moment", () => {
  const moment = jest.requireActual("moment");
  moment.tz.setDefault("America/New_York");
  return moment;
});

const mockAsyncStorage = require("@react-native-community/async-storage/jest/async-storage-mock");
github leifoolsen / webpack2-boilerplate / test / unit / utils / request.spec.js View on Github external
const textOk = (body) => {
  const mockResponse = new Response(body, {
    status: 200,
    headers: {
      'Content-type': 'text/html; utf-8'
    }
  });
  return Promise.resolve(mockResponse);
};
github leifoolsen / webpack2-boilerplate / test / unit / utils / request.spec.js View on Github external
const jsonError = (status, statusText) => {
  const mockResponse = new Response('', {
    status: status,
    statusText: statusText,
    headers: {
      'Content-type': 'application/json',
    },
  });
  return Promise.resolve(mockResponse);
};
github leifoolsen / webpack2-boilerplate / test / unit / logger / logger.spec.js View on Github external
const jsonOk = (body) => {
  const mockResponse = new Response(JSON.stringify(body), {
    status: 200,
    headers: {
      'Content-type': 'application/json'
    }
  });
  return Promise.resolve(mockResponse);
};
github leifoolsen / webpack2-boilerplate / test / unit / utils / request.spec.js View on Github external
const jsonOk = (body) => {
  const mockResponse = new Response(JSON.stringify(body), {
    status: 200,
    headers: {
      'Content-type': 'application/json; utf-8'
    }
  });
  return Promise.resolve(mockResponse);
};
github cube-js / cube.js / packages / cubejs-playground / src / ExplorePage.js View on Github external
async componentDidMount() {
    const res = await fetch('/playground/context');
    const result = await res.json();
    this.setState({
      cubejsToken: result.cubejsToken,
      apiUrl: result.apiUrl || window.location.href.split('#')[0].replace(/\/$/, '')
    });
  }

whatwg-fetch

A window.fetch polyfill.

MIT
Latest version published 1 year ago

Package Health Score

85 / 100
Full package analysis