How to make HTTP requests using "fetch"

How to make HTTP requests using "fetch"

Dhairya Shah's photo
Dhairya Shah
ยทJan 9, 2022ยท

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

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

ย 
Share this