Skip to content

Instantly share code, notes, and snippets.

@dtanphat9388
Last active April 27, 2018 05:43
Show Gist options
  • Save dtanphat9388/d16103e89c132cbf321b2688671d7934 to your computer and use it in GitHub Desktop.
Save dtanphat9388/d16103e89c132cbf321b2688671d7934 to your computer and use it in GitHub Desktop.
Request data in Electron
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