Skip to content

Instantly share code, notes, and snippets.

@Ebazhanov
Created August 9, 2021 18:59
Show Gist options
  • Save Ebazhanov/30ce06b55e8d9b4aea5169ab6ab4a3af to your computer and use it in GitHub Desktop.
Save Ebazhanov/30ce06b55e8d9b4aea5169ab6ab4a3af to your computer and use it in GitHub Desktop.
// https://learn.javascript.ru/promise-chaining
// Запрашиваем user.json
fetch('/article/promise-chaining/user.json')
// Загружаем данные в формате json
.then(response => response.json())
// Делаем запрос к GitHub
.then(user => fetch(`https://api.github.com/users/${user.name}`))
// Загружаем ответ в формате json
.then(response => response.json())
// Показываем аватар (githubUser.avatar_url) в течение 3 секунд (возможно, с анимацией)
.then(githubUser => {
let img = document.createElement('img');
img.src = githubUser.avatar_url;
img.className = "promise-avatar-example";
document.body.append(img);
setTimeout(() => img.remove(), 3000); // (*)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment