electron-main-fetch:在Electron的主要进程中使用浏览器Fetch API
electron-main-fetch:在Electron的主要进程中使用浏览器Fetch API
Node.js 网络处理
共32Star
详细介绍
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
- electron-config - Simple config handling for your Electron app or module
- electron-debug - Adds useful debug features to your Electron app
- electron-context-menu - Context menu for your Electron app
- electron-dl - Simplified file downloads for your Electron app
- electron-unhandled - Catch unhandled errors and promise rejections in your Electron app
License
MIT © Sindre Sorhus