Last active
April 5, 2019 15:03
-
-
Save prohazko2/4cf267f6476722cc72eebb271a1d25e7 to your computer and use it in GitHub Desktop.
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
const v1 = `https://${process.env.RIC_HOST}/api/v1`; | |
const login = process.env.RIC_USER; | |
const password = process.env.RIC_PASS; | |
async function getToken() { | |
const resp = await fetch(`${v1}/auth/token`, { | |
method: 'post', | |
headers: { 'Content-Type': 'application/json' }, | |
body: JSON.stringify({ login, password }) | |
}); | |
const { token } = await resp.json(); | |
return token; | |
} | |
async function getObjects() { | |
const token = await getToken(); | |
const objects = await fetch(`${v1}/objects`, { | |
headers: { 'Authorization': `Bearer ${token}` }, | |
}); | |
return await objects.json(); | |
} | |
getObjects().then(objects => | |
console.log('objects', objects)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment