Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 9, 2022 04:19 pm GMT

How to make HTTP requests using "fetch"

Hello

Method 1 - Promise

fetch('https://randomuser.me/api/').then(res => res.json()).then(data => {    console.log(data)})

Method 2 - Async

const response = await fetch('https://randomuser.me/api/')const data = response.json()console.log(data)

*Note: Make sure function is async *

Thank you for reading


Original Link: https://dev.to/codewithsnowbit/how-to-make-http-requests-using-fetch-1hj8

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To