How to use fetch-ponyfill - 10 common examples

To help you get started, we’ve selected a few fetch-ponyfill 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 DigixGlobal / truffle-lightwallet-provider / node_modules / web3-provider-engine / subproviders / fetch.js View on Github external
const fetch = global.fetch || require('fetch-ponyfill')().fetch
const inherits = require('util').inherits
const retry = require('async/retry')
const waterfall = require('async/waterfall')
const asyncify = require('async/asyncify')
const JsonRpcError = require('json-rpc-error')
const promiseToCallback = require('promise-to-callback')
const createPayload = require('../util/create-payload.js')
const Subprovider = require('./subprovider.js')

const RETRIABLE_ERRORS = [
  // ignore server overload errors
  'Gateway timeout',
  'ETIMEDOUT',
  // ignore server sent html error pages
  // or truncated json responses
  'SyntaxError',
github Azure / ms-rest-js / dist / lib / util / utils.js View on Github external
function getFetch() {
    // using window.Fetch in Edge gives a TypeMismatchError
    // (https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8546263/).
    // Hence we will be using the fetch-ponyfill for Edge.
    if (typeof window !== "undefined" && window.fetch && window.navigator &&
        window.navigator.userAgent && window.navigator.userAgent.indexOf("Edge/") === -1) {
        return window.fetch.bind(window);
    }
    return require("fetch-ponyfill")({ useCookie: true }).fetch;
}
exports.getFetch = getFetch;
github MetaMask / eth-json-rpc-middleware / fetch.js View on Github external
const fetch = global.fetch || require('fetch-ponyfill')().fetch
const url = require('url')
const { errors: rpcErrors } = require('eth-json-rpc-errors')
const btoa = require('btoa')
const createAsyncMiddleware = require('json-rpc-engine/src/createAsyncMiddleware')


module.exports = createFetchMiddleware
module.exports.createFetchConfigFromReq = createFetchConfigFromReq

const RETRIABLE_ERRORS = [
  // ignore server overload errors
  'Gateway timeout',
  'ETIMEDOUT',
  // ignore server sent html error pages
  // or truncated json responses
  'failed to parse response body',
github TheScienceMuseum / collectionsonline / client / routes / search.js View on Github external
var QueryString = require('querystring');
var fetch = require('fetch-ponyfill')().fetch;
var page = require('page');
var Snackbar = require('snackbarlightjs');

var Templates = require('../templates');

var parseParams = require('../../routes/route-helpers/parse-params.js');

var createQueryParams = require('../../lib/query-params/query-params');
var paramify = require('../../lib/helpers/paramify.js');
var querify = require('../../lib/helpers/querify.js');
var searchResultsToTemplateData = require('../../lib/transforms/search-results-to-template-data');

var getData = require('../lib/get-data.js');
var filterResults = require('../lib/filter-results');
var filterState = require('../lib/filter-state.js');
var toggleFacets = require('../lib/toggle-facets.js');
github TheScienceMuseum / collectionsonline / client / lib / get-data.js View on Github external
var fetch = require('fetch-ponyfill')().fetch;

module.exports = function (url, opts, cb) {
  fetch(url, opts)
    .then(function (res) {
      if (res.ok) {
        return res.json();
      } else {
        return Promise.reject(new Error(res.status + ' Failed to fetch results'));
      }
    })
    .then(function (json) {
      if (json.errors) {
        return Promise.reject(json.errors[0]);
      }
      return cb(null, json);
    })
github alanshaw / embed-video / index.js View on Github external
var URL = require('url')
var promise = require('promise-polyfill')
var fetch = require('fetch-ponyfill')({ Promise: promise }).fetch
var escape = require('lodash.escape')

var YOUTUBE = 'youtube'
var VIMEO = 'vimeo'
var DAILYMOTION = 'dailymotion'

var validVimeoOpts = [
  'thumbnail_small',
  'thumbnail_medium',
  'thumbnail_large'
]
var validYouTubeOpts = [
  'default',
  'mqdefault',
  'hqdefault',
  'sddefault',
github benjamine / fetch-wrap / src / benchmark.js View on Github external
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite();

const fetchExtend = require('./main');
const middleware = require('./middleware');

const http = require('http');
const port = process.env.PORT || 8080;

const fetch = require('fetch-ponyfill')().fetch;

const logBuffer = [];
const extendedFetch = fetchExtend(fetch, [
  middleware.urlParams({
    host: 'localhost'
  }),
  middleware.optionsByUrlPattern([
    {
      for: 'http://localhost*',
      options: {
        headers: {
          'Authorization': 'Token 1234'
        }
      }
    }
  ]),
github ccxt / ccxt / build / postinstall.js View on Github external
const fetch = require ('fetch-ponyfill') ().fetch

function style(s, style) {
    return style + s + '\033[0m'
}

const colors = {
    'black': 30,
    'red': 31,
    'green': 32,
    'yellow': 33,
    'blue': 34,
    'white': 37,
    'gray': 90,
}

let colorFunctions = {}
github Azure / ms-rest-js / dist / lib / fetchHttpClient.js View on Github external
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var httpHeaders_1 = require("./httpHeaders");
/**
 * The cached fetch method that will be used to send HTTP requests.
 */
var fetch = require("fetch-ponyfill")({ useCookie: true }).fetch;
/**
 * A HttpClient implementation that uses fetch to send HTTP requests.
 */
var FetchHttpClient = /** @class */ (function () {
    function FetchHttpClient() {
    }
    FetchHttpClient.prototype.send = function (request) {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            var fetchRequestOptions, fetchResponse, responseHeaders, fetchResponseHeaders;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        fetchRequestOptions = {
                            method: request.httpMethod,
                            headers: request.headers.toJson(),
github bsdavidson / trimetric / web / src / index.jsx View on Github external
import "whatwg-fetch";
import fetchPonyfill from "fetch-ponyfill";
import ReactDOM from "react-dom";
import {BrowserRouter} from "react-router-dom";

import {render} from "./router";
import {Trimet} from "./data";
import {store} from "./store";

const trimet = new Trimet(store, fetchPonyfill().fetch);
trimet.start();

window.addEventListener("load", () => {
  ReactDOM.render(
    render(store, trimet.handleStopChange, {Router: BrowserRouter}),
    document.getElementById("app")
  );
});

fetch-ponyfill

A ponyfill (doesn't overwrite the native fetch) for the Fetch specification https://fetch.spec.whatwg.org.

MIT
Latest version published 4 years ago

Package Health Score

61 / 100
Full package analysis

Popular fetch-ponyfill functions