Skip to content

Instantly share code, notes, and snippets.

@crivotz
Created Apr 3, 2020
Embed
What would you like to do?
Fetch example
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