1
2
3
4
5
6
7
8
9
10
// fetch data (old way)
function getUser(id) {
  return fetch('/api/users/' + id)
    .then(function(res) {
      return res.json();
    })
    .then(function(data) {
      return data.user;
    });
}
1
2
3
4
5
6
// fetch data (new way)
async function getUser(id) {
  const res = await fetch(`/api/users/${id}`);
  const { user } = await res.json();
  return user;
}