Created
February 8, 2026 13:52
-
-
Save vanaf1979/6d1bfdfd66ebe7d53d2fa8c999fc1dbe to your computer and use it in GitHub Desktop.
Fetch Await
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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