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() }) }
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; }
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); }); }
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), }); }
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) }
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}`, }, }); }
fetch.mockImplementation(() => Promise.resolve({ statusText: "" }));
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); }
const fetchStory = async (storyId) => { return (await fetch(`https://hacker-news.firebaseio.com/v0/item/${storyId}.json`)).json(); }
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) }
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) }
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), }); }
const fetchUser = async (userId) => { return (await fetch(`https://hacker-news.firebaseio.com/v0/user/${userId}.json`)).json(); }
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) }