Skip to content

Instantly share code, notes, and snippets.

@vanaf1979
Created February 8, 2026 13:52
Show Gist options
  • Select an option

  • Save vanaf1979/6d1bfdfd66ebe7d53d2fa8c999fc1dbe to your computer and use it in GitHub Desktop.

Select an option

Save vanaf1979/6d1bfdfd66ebe7d53d2fa8c999fc1dbe to your computer and use it in GitHub Desktop.
Fetch Await
const getUserData = async () => {
try {
const userResponse = await fetch('https://api.example.com/user/1');
const user = await userResponse.json();
const postsResponse = await fetch(`https://api.example.com/posts?userId=${user.id}`);
const posts = await postsResponse.json();
console.log(`User: ${user.name}, Posts: ${posts.length}`);
} catch (error) {
console.error('Something went wrong:', error);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment