Skip to content

Instantly share code, notes, and snippets.

@crivotz
Created April 3, 2020 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crivotz/25c82546a8b5894406034134aeefa72f to your computer and use it in GitHub Desktop.
Save crivotz/25c82546a8b5894406034134aeefa72f to your computer and use it in GitHub Desktop.
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