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); }
fetchPromise.then(res => { response = { statusCode: res.status, headers: res.headers }; return opts.json ? res.json() : res.text(); }) .then(
request(url, timeout) { return fetch(url, { timeout: timeout }).then((response) => { return Promise.resolve(response.text()); }); }
const fetchResource = async (url) => { const response = await fetch(url) const html = await response.text() const resource = await metascraper({ html, url }) return { sources: ['resource'], ...resource, } }
it('should detect the language of code', async () => { expect.hasAssertions(); const res = await fetch(server, { method: 'POST', body: 'const a = "b";' }); const body = await res.text(); expect(body).toEqual('JavaScript'); })
app.use('/json', (req, res) => { fetch('https://medium.com/@<account>/latest?format=json') .then((response) => { console.log("Data recieved!"); res.status(200); res.contentType('application/json'); response.text().then(json => res.send(new MParse().getArticles(json))); }) .catch((err) => { console.log("Failed to get data."); }); });
var parseWebsite = async function parseWebsite(website) { try { var url = normalizeUrl(website); var html = await fetch(url).then(function (res) { return res.text(); }); var $ = load(html); var handles = {}; module.exports.CONFIG.socialNetworks.forEach(function (socialNetwork) { handles[socialNetwork] = parse(socialNetwork)($); }); return handles; } catch (error) { throw new Error('Error fetching website data for ' + website + ': ' + error.message); } }
const response = await fetch(url); const timeEnd = new Date(); const text = await response.text(); await makeDir(dirName); await writeFile(dist, text);
fetch(API_ENDPOINT, { method: "POST", body: event.body, headers: { "Content-Type": "application/json", accept: "*/*" } }) .then(response => { console.log(response); if (response.status !== 200) { throw new Error("Error from bahnql endpoint"); } return response.text(); }) .then(json => ({ statusCode: 200, body: json })) .catch(error => ({ statusCode: 422, body: String(error) }))
async _loadFile(filePath) { debug('docsify')(`load > ${filePath}`) let content try { if (isAbsolutePath(filePath)) { const res = await fetch(filePath) if (!res.ok) { throw Error() } content = await res.text() this.lock = 0 } else { content = await readFileSync(filePath, 'utf8') this.lock = 0 } return content } catch (e) { this.lock = this.lock || 0 if (++this.lock > 10) { this.lock = 0 return } const fileName = basename(filePath) const result = await this._loadFile(resolvePathname(`../${fileName}`, filePath)) return result } }
(async () => { const res = await fetch(sha256Url) const text = await res.text() const matchLine = text.split('\n').find(line => line.includes(fileName)) if (matchLine) {
throw new BadResponse(status); const xml = await response.text(); success = parse(xml, includeEntry); break;
const parseWebsite = async website => { try { const url = normalizeUrl(website) const html = await fetch(url).then(res => res.text()) const $ = load(html) let handles = {} module.exports.CONFIG.socialNetworks.forEach(socialNetwork => { handles[socialNetwork] = parse(socialNetwork)($) }) return handles } catch (error) { throw new Error( `Error fetching website data for ${website}: ${error.message}`, ) } }
async _loadFile(filePath) { debug('docsify')(`load > ${filePath}`) let content try { if (isAbsolutePath(filePath)) { const res = await fetch(filePath) if (!res.ok) { throw Error() } content = await res.text() this.lock = 0 } else { content = await readFileSync(filePath, 'utf8') this.lock = 0 } return content } catch (e) { this.lock = this.lock || 0 if (++this.lock > 10) { this.lock = 0 return } const fileName = basename(filePath) const result = await this._loadFile(resolvePathname(`../${fileName}`, filePath)) return result } }
const response = await fetch(url); const timeEnd = new Date(); const text = await response.text(); await makeDir(dirName); await writeFile(dist, text);