How to use the node-fetch.default 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 pd4d10 / octohint / scripts / get-lib-names.js View on Github external
async function main() {
  //   const res = await fetch('https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/notNeededPackages.json')
  //   const { packages } = await res.json()
  try {
    const r0 = await fetch('https://api.github.com/repos/DefinitelyTyped/DefinitelyTyped/git/trees/master')
    const { tree: t0 } = await r0.json()
    const { url } = t0.filter(({ path }) => path === 'types')[0]
    const r1 = await fetch(url)
    const { tree: t1 } = await r1.json()
    const libs = t1.map(({ path }) => path)
    const content = `module.exports = ${JSON.stringify(libs)}`

    fs.writeFileSync(path.resolve(__dirname, '../src/libs.js'), content)
  } catch (err) {
    console.log(err)
  }
}
github pulumi / pulumi-awsx / nodejs / examples / dashboards / index.ts View on Github external
const subscription = topic.onEvent("for-each-url", async (event) => {
    const records = event.Records || [];
    for (const record of records) {
        const url = record.Sns.Message;

        console.log(`${url}: Processing`);

        // Fetch the contents at the URL
        console.log(`${url}: Getting`);
        try {
            const res = await fetch.default(url);
        } catch (err) {
            console.log(`${url}: Failed to GET`);
            return;
        }
    }
});
github jakejrichards / cod-api / index.js View on Github external
function getDataFromAPI(uri) {
    return node_fetch_1["default"](uri)
        .then(function (response) { return response.json(); })
        .then(function (response) {
        var status = response.status, error = response.data;
        if (status !== 'success') {
            throw new Error("cod-api request failed: " + error.message);
        }
        return response;
    });
}
// API Methods
github rockstat / chwriter / dist / clickhouse / CHClient.js View on Github external
async execute(body) {
        const queryUrl = this.url + '/?' + qs.stringify(this.params);
        let responseBody;
        // try {
        const res = await node_fetch_1.default(queryUrl, {
            method: constants_1.METHOD_POST,
            body: body,
            timeout: this.timeout
        });
        responseBody = await res.text();
        if (!res.ok) {
            throw new Error(responseBody);
        }
        // } catch (error) {
        //   throw error;
        // }
        return responseBody;
    }
    /**
github contiamo / operational-ui / lambdas / notify-slack-on-deploy.js View on Github external
exports.handler = async (event) => {
  try {
    console.log(JSON.stringify(event, null, 2))
    const requestBody = JSON.parse(event.body)

    if (!get(requestBody, "attachments.0.title_link", "").includes("deploy-preview")) {
      return defaultResponse
    }

    await fetch(process.env.SLACK_WEBHOOK_URL, {
      method: "POST",
      body: JSON.stringify({
        ...requestBody,
        text: "🎉 One of my PRs now has a demo!",
        username: "Operational UI",
        icon_url: "https://emoji.slack-edge.com/T0G7GJQ9Z/operational/d2230b6586af99f0.png",
        attachments: [
          {
            ...get(requestBody, "attachments.0", {}),
            fallback: "🎉 One of my PRs now has a demo!",
            text: "Also, the PR is  if you want to review it.",
            footer: "Thank you for your amazing contribution to this team.",
          },
        ],
      }),
    })
github vikerman / ivy-universal / src / lib / server / fetch.ts View on Github external
return (url: string) : Promise => {
    if (!url.startsWith('http://') && !url.startsWith('https://')) {
      if (url.startsWith('/')) {
        url = url.substr(1);
      }
      url = `http://${host}:${port}/${url}`;
    }
    return fetch(url);
  }
}
github ampproject / ampbench / amp-story / linter / index.ts View on Github external
function canXhrCache(context: Context, xhrUrl: string, cacheSuffix: string) {
  const sourceOrigin = buildSourceOrigin(context.url);
  const origin = buildCacheOrigin(cacheSuffix, context.url);

  const headers = Object.assign(
    {},
    {origin},
    context.headers
  );

  const curl = fetchToCurl(addSourceOrigin(xhrUrl, sourceOrigin), { headers });

  return fetch(addSourceOrigin(xhrUrl, sourceOrigin), {headers})
    .then(isStatusOk)
    .then(isAccessControlHeaders(origin, sourceOrigin))
    .then(isJson)
    .then(PASS, (e) => FAIL(`can't retrieve bookend: ${e.message} [debug: ${curl}]`));
}
github dolthub / dolt / samples / js / fb / slurp / src / main.js View on Github external
function callFacebookRaw(url: string): Promise {
  return fetch(new Request(url, {
    headers: new Headers(
      {'Authorization': `Bearer ${args['access-token']}`}),
  }));
}
github firebase / extensions / slack-messenger / functions / lib / index.js View on Github external
exports.slackMessenger = functions.handler.pubsub.topic.onPublish((message) => __awaiter(this, void 0, void 0, function* () {
    logs.start();
    try {
        const { text } = message.json;
        if (!text) {
            logs.textMissing();
            return;
        }
        logs.messageSending(config_1.default.slackWebhookUrl);
        yield node_fetch_1.default(config_1.default.slackWebhookUrl, {
            method: "POST",
            body: JSON.stringify({ text }),
            headers: {
                "Content-Type": "application/json",
            },
        });
        logs.messageSent(config_1.default.slackWebhookUrl);
        logs.complete();
    }
    catch (err) {
        logs.error(err);
    }
}));