const BASE = `https://dummyapi.io/data/api/` function get_collection(collection) { let request = new XMLHttpRequest(); request.open('GET', `${BASE}${collection}`); request.setRequestHeader('app-id', '5f76987a523f015e7c5ae49b'); request.onload = function () { let prefix = collection.includes('/') ? '' : `
gender: ${r.gender}
email: ${r.email}
date of birth: ${r.dateOfBirth}
register date: ${r.registerDate}
phone: ${r.phone}
picture: ${r.picture}
location: ${l.street}, ${l.city}, ${l.state}, ${l.country}
` } function post_format(r) { return r.data.map(comment => `${comment.message}
`).join("\n"); } function get_member(collection, member) { let request = new XMLHttpRequest(); console.log(`${BASE}${collection}/${member}`); request.open('GET', `${BASE}${collection}/${member}`); request.setRequestHeader('app-id', '5f76987a523f015e7c5ae49b'); request.onload = function () { let format = collection == 'user' ? user_format : post_format; document.getElementById(member).innerHTML = format( JSON.parse(request.response)); } request.send(); }