How to use the whatwg-fetch.fetch function in whatwg-fetch

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 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(/\/$/, '')
    });
  }
github MageStudio / Mage / src / base / App.js View on Github external
loadScene = (url = this.getJSONUrl()) => {
        if (getWindow()) {
            return fetch(url)
                .then(res => res.json())
                .then(this.parseScene)
                .catch(() => Promise.resolve());
        }
        return Promise.resolve();
    }
github daud-io / daud / Game.Engine / wwwroot / js / serverinfo.js View on Github external
import "babel-polyfill";

import { fetch } from "whatwg-fetch";
import * as dat from "dat.gui";

export const gui = new dat.GUI({ width: 500 });

const hooks = {};

const token = fetch("/api/v1/user/authenticate", {
    method: "POST",
    headers: {
        "Content-Type": "application/json; charset=utf-8"
    },
    body: JSON.stringify({
        Identifier: {
            UserKey: "Administrator"
        },
        password: prompt("What is the password")
    })
})
    .then(r => r.json())
    .then(({ response }) => response.token)
    .then(r => {
        fetch("/api/v1/server/hook", {
            method: "POST",
github Feverqwe / tSearch / src / tools / exKitRequest.js View on Github external
const fetchRequest = (url, fetchOptions) => {
  const controller = new AbortController();

  const request = fetch(url, {
    method: fetchOptions.method,
    headers: fetchOptions.headers,
    body: fetchOptions.body,
    signal: controller.signal
  }).then(response => {
    if (!response.ok) {
      throw new StatusCodeError(response.status, null, null, response);
    }

    return response.arrayBuffer().then(arrayBuffer => {
      return {response, arrayBuffer};
    });
  });

  request.abort = () => {
    controller.abort();
github JetBrains / kotlin-playground / src / webdemo-api.js View on Github external
"confType": targetPlatform.id,
    "originUrl": null,
    "files": files,
    "readOnlyFileNames": []
  });

  const body = new URLSearchParams();
  body.set('filename', DEFAULT_FILE_NAME);
  body.set('project', projectJson);

  if (options !== undefined) {
    for (let option in options) {
      body.set(option, options[option])
    }
  }
  return fetch(url + targetPlatform.id, {
    method: 'POST',
    body: body.toString(),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  }).then(response => response.json())
}
github mongodb / stitch-js-sdk / packages / browser / core / src / core / internal / net / BrowserFetchTransport.ts View on Github external
public roundTrip(request: BasicRequest): Promise {
    const responsePromise = fetch(request.url, {
      body: request.body,
      headers: request.headers,
      method: request.method,
      mode: 'cors'
    });

    const responseTextPromise = responsePromise.then(response =>
      response.text()
    );

    return Promise.all([responsePromise, responseTextPromise]).then(values => {
      const response = values[0];
      const body = values[1];
      const headers: { [key: string]: string } = {};
      response.headers.forEach((value, key) => {
        headers[key] = value;

whatwg-fetch

A window.fetch polyfill.

MIT
Latest version published 4 months ago

Package Health Score

93 / 100
Full package analysis