Created
April 3, 2020 12:52
-
-
Save crivotz/25c82546a8b5894406034134aeefa72f to your computer and use it in GitHub Desktop.
Fetch example
This file contains hidden or 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
async function init() { | |
try { | |
let login = await fetch('http://xxx.xxx.xxx.xxx/api/login', { | |
method: 'POST', | |
body: JSON.stringify({login: 'user', password: 'password'}), | |
}).then(response => response.json()); | |
let action = await fetch('http://xxx.xxx.xxx.xxx/api/action', { | |
method: 'GET', | |
headers: {'Authorization': login.token}, | |
}).then(response => response.json()); | |
let action1 = await fetch('http://xxx.xxx.xxx.xxx/api/action1', { | |
method: 'GET', | |
headers: {'Authorization': login.token}, | |
}).then(response => response.json()); | |
return {devices, absolute_layouts}; | |
} catch (e) { | |
console.log('ciao'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment