Skip to content

Instantly share code, notes, and snippets.

@prohazko2
Last active April 5, 2019 15:03
Show Gist options
  • Save prohazko2/4cf267f6476722cc72eebb271a1d25e7 to your computer and use it in GitHub Desktop.
Save prohazko2/4cf267f6476722cc72eebb271a1d25e7 to your computer and use it in GitHub Desktop.
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