DEV Community

Cover image for How to make HTTP requests using "fetch"
Dhairya Shah
Dhairya Shah

Posted on • Originally published at codewithsnowbit.hashnode.dev

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)
})
Enter fullscreen mode Exit fullscreen mode

Method 2 - Async

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

*Note: Make sure function is async *


Thank you for reading

Top comments (0)