How to make HTTP requests using "fetch"

How to make HTTP requests using "fetch"

Jan 9, 2022ยท

1 min read

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

ย