Skip to main content

Command Palette

Search for a command to run...

How to make HTTP requests using "fetch"

Published
β€’1 min read
How to make HTTP requests using "fetch"
D

I am 17 years old and a young passionate and self-taught frontend web developer and have an intention to become a successful developer. I usually write about JavaScript and Web Development and share some tips in the articles.

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

More from this blog

D

Dhairya Shah

119 posts