How to make HTTP requests using "fetch"

How to make HTTP requests using "fetch"

ยท

1 min read

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

ย