Tabnine Logo For Javascript
node-fetch
Code IndexAdd Tabnine to your IDE (free)

How to use node-fetch

Best JavaScript code snippets using node-fetch(Showing top 15 results out of 1,926)

origin: nodejs/nodejs.org

function sendRequest (opts) {
 const options = {
  headers: { 'User-Agent': 'nodejs.org release blog post script' },
  ...opts
 }

 return fetch(options.url, options).then(resp => {
  if (resp.status !== 200) {
   throw new Error(`Invalid status code (!= 200) while retrieving ${options.url}: ${resp.status}`)
  }
  return options.json ? resp.json() : resp.text()
 })
}
origin: cube-js/cube.js

async manifestJSON() {
  const response = await fetch(
   `https://api.github.com/repos/${this.repo.owner}/${this.repo.name}/contents/manifest.json`
  );

  return JSON.parse(Buffer.from((await response.json()).content, 'base64').toString());
 }
origin: withspectrum/spectrum

const processJob = async () => {
 debug('pinging compose to start on-demand db backup');
 const result = await compose(
  `2016-07/deployments/${COMPOSE_DEPLOYMENT_ID}/backups`,
  {
   method: 'POST',
  }
 );
 const json = await result.json();
 debug(json);
 return;
}
origin: cube-js/cube.js

async downloadRepo() {
  const url = `https://github.com/${this.repo.owner}/${this.repo.name}/archive/master.tar.gz`;
  const writer = fs.createWriteStream(this.repoArchivePath);

  (await fetch(url)).body.pipe(writer);

  return new Promise((resolve, reject) => {
   writer.on('finish', resolve);
   writer.on('error', reject);
  });
 }
origin: builderbook/builderbook

function callAPI({ path, method, data }) {
 const ROOT_URI = `https://${process.env.MAILCHIMP_REGION}.api.mailchimp.com/3.0`;

 return fetch(`${ROOT_URI}${path}`, {
  method,
  headers: {
   Accept: 'application/json',
   Authorization: `Basic ${Buffer.from(`apikey:${process.env.MAILCHIMP_API_KEY}`).toString(
    'base64',
   )}`,
  },
  body: JSON.stringify(data),
 });
}
origin: filipedeschamps/cep-promise

export default function fetchBrasilAPIService (cepWithLeftPad) {
 const url = `https://brasilapi.com.br/api/cep/v1/${cepWithLeftPad}`
 const options = {
  method: 'GET',
  mode: 'cors',
  headers: {
   'content-type': 'application/json;charset=utf-8'
  }
 }

 return fetch(url, options)
  .then(parseResponse)
  .then(extractCepValuesFromResponse)
  .catch(throwApplicationError)
}
origin: withspectrum/spectrum

const compose = (path: string, fetchOptions?: Object = {}) => {
 if (!COMPOSE_API_TOKEN) {
  throw new Error('Please specify the COMPOSE_API_TOKEN env var.');
 }
 return fetch(`https://api.compose.io/${path}`, {
  ...fetchOptions,
  headers: {
   'Content-Type': 'application/json',
   ...(fetchOptions.headers || {}),
   Authorization: `Bearer ${COMPOSE_API_TOKEN}`,
  },
 });
}
origin: moleculerjs/moleculer

fetch.mockImplementation(() => Promise.resolve({ statusText: "" }));
origin: Netflix/pollyjs

export default async function fetch() {
 const res = await this.page.evaluate((...args) => {
  // This is run within the browser's context meaning it's using the
  // browser's native window.fetch method.
  return fetch(...args).then(res => {
   const { url, status, headers } = res;

   return res.text().then(body => {
    return { url, status, body, headers };
   });
  });
 }, ...arguments);

 return new Response(res.body, res);
}
origin: cube-js/cube.js

const fetchStory = async (storyId) => {
 return (await fetch(`https://hacker-news.firebaseio.com/v0/item/${storyId}.json`)).json();
}
origin: filipedeschamps/cep-promise

export default function fetchCorreiosService (cepWithLeftPad, proxyURL = '') {
 const url = `${proxyURL}https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente`
 const options = {
  method: 'POST',
  body: `<?xml version="1.0"?>\n<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">\n  <soapenv:Header />\n  <soapenv:Body>\n    <cli:consultaCEP>\n      <cep>${cepWithLeftPad}</cep>\n    </cli:consultaCEP>\n  </soapenv:Body>\n</soapenv:Envelope>`,
  headers: {
   'Content-Type': 'text/xml;charset=UTF-8',
   'cache-control': 'no-cache'
  }
 }

 return fetch(url, options)
  .then(analyzeAndParseResponse)
  .catch(throwApplicationError)
}
origin: filipedeschamps/cep-promise

export default function fetchViaCepService (cepWithLeftPad, proxyURL = '') {
 const url = `${proxyURL}https://viacep.com.br/ws/${cepWithLeftPad}/json/`
 const options = {
  method: 'GET',
  mode: 'cors',
  headers: {
   'content-type': 'application/json;charset=utf-8'
  }
 }

 return fetch(url, options)
  .then(analyzeAndParseResponse)
  .then(checkForViaCepError)
  .then(extractCepValuesFromResponse)
  .catch(throwApplicationError)
}
origin: builderbook/builderbook

function callAPI({ path, method, data }) {
 const ROOT_URI = `https://${process.env.MAILCHIMP_REGION}.api.mailchimp.com/3.0`;

 return fetch(`${ROOT_URI}${path}`, {
  method,
  headers: {
   Accept: 'application/json',
   Authorization: `Basic ${Buffer.from(`apikey:${process.env.MAILCHIMP_API_KEY}`).toString(
    'base64',
   )}`,
  },
  body: JSON.stringify(data),
 });
}
origin: cube-js/cube.js

const fetchUser = async (userId) => {
 return (await fetch(`https://hacker-news.firebaseio.com/v0/user/${userId}.json`)).json();
}
origin: filipedeschamps/cep-promise

export default function fetchWideNetService (cepWithLeftPad, proxyURL = '') {
 const url = `${proxyURL}https://cep.widenet.host/busca-cep/api/cep/${cepWithLeftPad}.json`
 const options = {
  method: 'GET',
  mode: 'cors',
  headers: {
   'content-type': 'application/json;charset=utf-8'
  }
 }

 return fetch(url, options)
  .then(analyzeAndParseResponse)
  .then(checkForWideNetError)
  .then(extractCepValuesFromResponse)
  .catch(throwApplicationError)
}
node-fetch(npm)

JSDoc

A light-weight module that brings window.fetch to node.js

Most used node-fetch functions

  • fetch
  • Response.json
  • Response.text
  • Response.status
  • Response.body
  • Headers,
  • Response.buffer,
  • Response.headers,
  • Response.ok,
  • Response.statusText,
  • default,
  • mockClear,
  • Headers.get,
  • Response.url,
  • mockImplementation,
  • FETCH,
  • Headers._headers,
  • Headers.append,
  • Headers.set

4 Minute Read

How to Use The Array forEach() Method in JavaScript

Popular in JavaScript

  • path
  • yargs
    yargs the modern, pirate-themed, successor to optimist.
  • q
    A library for promises (CommonJS/Promises/A,B,D)
  • superagent
    elegant & feature rich browser / node HTTP with a fluent API
  • handlebars
    Handlebars provides the power necessary to let you build semantic templates effectively with no frustration
  • mocha
    simple, flexible, fun test framework
  • through2
    A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise
  • glob
    a little globber
  • moment
    Parse, validate, manipulate, and display dates
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now