electron-main-fetch:在Electron的主要进程中使用浏览器Fetch API

electron-main-fetch:在Electron的主要进程中使用浏览器Fetch API

Node.js 网络处理

访问GitHub主页

共32Star

详细介绍

electron-main-fetch Build Status

Use the browser Fetch API from the main process in Electron

Proof of concept. Comments welcome.

Install

$ npm install electron-main-fetch

Usage

The difference between this and Fetch is that instead of receiving a Response object and calling a method on it for what type to receive, you just specify the type in the function call.

const fetch = require('electron-main-fetch');

(async () => {
	const ip = await fetch('https://api.ipify.org', {type: 'text'});
	console.log(ip);
	//=> '170.56.15.35'
})();

With Fetch in the renderer process, the above would instead be:

(async () => {
	const ip = await fetch('https://api.ipify.org').then(response => response.text());
	console.log(ip);
	//=> '170.56.15.35'
})();

API

fetch(input, options)

Same options as Fetch, but also:

type

Type: string
Values: json text formData blob arrayBuffer
Default: json

Related

License

MIT © Sindre Sorhus

推荐源码