Skip to content

Instantly share code, notes, and snippets.

@azjezz
Last active October 31, 2019 19:47
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 azjezz/35037a4bb4cd44236566bf346da4ba2c to your computer and use it in GitHub Desktop.
Save azjezz/35037a4bb4cd44236566bf346da4ba2c to your computer and use it in GitHub Desktop.
function user(uuid) {
let headers = new Headers({
'Accept': 'application/json'
})
let request = new Request('https://connect.symfony.com/api/users/' + uuid, {
method: 'GET',
headers: headers,
mode: 'cors',
cache: 'default'
})
return fetch(request).then(response => response.json()).then(user => {
let data = {
'name': user.name,
'username': user.username,
'dashboard': 'https://connect.symfony.com/admin/user/' + uuid,
}
user._links.forEach((link) => {
if (link.type.startsWith('image')) {
data.avatar = link.href
} else if ('text/html' === link.type) {
data.profile = link.href
}
})
return data
})
}
user('some-uuid').then(user => {
// user = { name: ..., username: ..., dashboard: ..., avatar: ..., profile: ... }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment