Skip to content

Instantly share code, notes, and snippets.

@mojaray2k
Last active April 29, 2020 15:30
Show Gist options
  • Save mojaray2k/fec9be09364eddaa7e4e29b893cd0605 to your computer and use it in GitHub Desktop.
Save mojaray2k/fec9be09364eddaa7e4e29b893cd0605 to your computer and use it in GitHub Desktop.
Using Async/Await

Here are some examples of using Async/Await

// function fetchAlbums(){
//   fetch('https://rallycoding.herokuapp.com/api/music_albums')
//     .then(res => res.json())
//     .then(json => console.log(json))
// }

// console.log(fetchAlbums());

// async function fetchAlbums() {
//   const res = await fetch('https://rallycoding.herokuapp.com/api/music_albums');
//   const json = await res.json();
//   console.log(json);
// }

// fetchAlbums();

const fetchAlbums = async () => {
  const res = await fetch('https://rallycoding.herokuapp.com/api/music_albums');
  const json = await res.json();
  console.log(json);
}

fetchAlbums();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment