How to use the node-fetch function in node-fetch

To help you get started, we’ve selected a few node-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 graphql-compose / graphql-compose-json / demo / utils.js View on Github external
return rp.args.urls.map(async url => {
        const res = await fetch(url);
        const data = await res.json();
        return data;
      });
    },
github molstar / molstar / src / servers / model / utils / fetch-retry.ts View on Github external
    const result = await retryIf(() => fetch(url, { timeout }), {
        retryThenIf: r => r.status >= 500 && r.status < 600,
github rickydunlop / fbmessenger-node / lib / MessengerClient.js View on Github external
linkAccount(accountLinkingToken) {
    const finalUrl = this.constructor.buildURL('me', {
      access_token: this.pageAccessToken,
      fields: 'recipient',
      account_linking_token: accountLinkingToken,
    });
    return fetch(finalUrl, {
      headers: {
        'Content-Type': 'application/json',
      },
    })
      .then(response => response.json());
  }
github Querijn / BottyMcBotface / src / RiotAPILibraries.ts View on Github external
private async getList(message: Discord.Message) {
        const response = await fetch(this.settings.riotApiLibraries.baseURL, this.fetchSettings);
        if (response.status !== 200) {
            message.channel.send(this.settings.riotApiLibraries.githubErrorList + response.status);
            return;
        }

        const data = await response.json() as GithubAPIStruct[];

        const languages = "`" + data.map(x => x.name).join(", ") + "`";
        const reply = this.settings.riotApiLibraries.languageList.replace("{languages}", languages);
        message.channel.send(reply);
    }
github prismicio / prismic-javascript / src / request.ts View on Github external
function fetchRequest(url: string, options: RequestHandlerOption, callback: RequestCallback): void {

  const fetchOptions = {
    headers: {
      Accept: 'application/json',
    },
  } as NodeRequestInit;

  if (options && options.proxyAgent) {
    fetchOptions.agent = options.proxyAgent;
  }

  fetch(url, fetchOptions).then((xhr) => {
    if (~~(xhr.status / 100 !== 2)) {
        /**
         * @description
         * drain the xhr before throwing an error to prevent memory leaks
         * @link https://github.com/bitinn/node-fetch/issues/83
         */
      return xhr.text().then(() => {
        const e: any = new Error(`Unexpected status code [${xhr.status}] on URL ${url}`);
        e.status = xhr.status;
        throw e;
      });
    } else {
      return xhr.json().then((result) => {
        const cacheControl = xhr.headers.get('cache-control');
        const parsedCacheControl = cacheControl ? /max-age=(\d+)/.exec(cacheControl) : null;
        const ttl = parsedCacheControl ? parseInt(parsedCacheControl[1], 10) : undefined;
github artsy / Mitosis / source / bot / artsy-api.js View on Github external
export async function getXappToken(): Promise {
  const clientAndSecret = `client_id=${ARTSY_API_CLIENT}&client_secret=${ARTSY_API_SECRET}`
  return fetch(`${GRAVITY_URL}${GravityXappAPI}?${clientAndSecret}`)
  .then(checkStatus)
  .then(parseJSON)
}
github OpenNeuroOrg / openneuro / packages / openneuro-server / graphql / resolvers / dataset.js View on Github external
export const onBrainlife = async dataset => {
  try {
    const url = `https://brainlife.io/api/warehouse/project?find={"openneuro.dataset_id":"${dataset.id}"}`
    const res = await fetch(url)
    const body = await res.json()
    return Boolean(body.count)
  } catch (err) {
    return false
  }
}
github reactioncommerce / reaction / src / core-services / account / util / expandAuthToken.js View on Github external
export default async function expandAuthToken(token) {
  const response = await fetch(HYDRA_OAUTH2_INTROSPECT_URL, {
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    method: "POST",
    body: qs.stringify({ token })
  });

  if (!response.ok) {
    throw new ReactionError("access-denied", "Error introspecting token");
  }

  return response.json();
}