Last active
April 27, 2018 05:43
-
-
Save dtanphat9388/d16103e89c132cbf321b2688671d7934 to your computer and use it in GitHub Desktop.
Request data in Electron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {app, BrowserWindow, net} from 'electron'; | |
function _setup() { | |
// ... | |
/** get data for app */ | |
let _strResult = ''; | |
let jsonResult; | |
let req = net.request({url: 'https://jsonplaceholder.typicode.com/users'}) | |
.on('response', res => { | |
res.on('data', chunk => _strResult += chunk ) | |
res.on('end', () => { | |
jsonResult = JSON.parse(_strResult) | |
console.log(jsonResult[0]) | |
console.log('end request') | |
}) | |
}) | |
req.end() | |
} | |
app.on('ready', _setup) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment