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)
})

Method 2 – Async

const response = await fetch(‘https://randomuser.me/api/’)
const …


This content originally appeared on DEV Community and was authored by SnowBit

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


This content originally appeared on DEV Community and was authored by SnowBit


Print Share Comment Cite Upload Translate Updates
APA

SnowBit | Sciencx (2022-01-09T16:19:39+00:00) How to make HTTP requests using “fetch”. Retrieved from https://www.scien.cx/2022/01/09/how-to-make-http-requests-using-fetch/

MLA
" » How to make HTTP requests using “fetch”." SnowBit | Sciencx - Sunday January 9, 2022, https://www.scien.cx/2022/01/09/how-to-make-http-requests-using-fetch/
HARVARD
SnowBit | Sciencx Sunday January 9, 2022 » How to make HTTP requests using “fetch”., viewed ,<https://www.scien.cx/2022/01/09/how-to-make-http-requests-using-fetch/>
VANCOUVER
SnowBit | Sciencx - » How to make HTTP requests using “fetch”. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/09/how-to-make-http-requests-using-fetch/
CHICAGO
" » How to make HTTP requests using “fetch”." SnowBit | Sciencx - Accessed . https://www.scien.cx/2022/01/09/how-to-make-http-requests-using-fetch/
IEEE
" » How to make HTTP requests using “fetch”." SnowBit | Sciencx [Online]. Available: https://www.scien.cx/2022/01/09/how-to-make-http-requests-using-fetch/. [Accessed: ]
rf:citation
» How to make HTTP requests using “fetch” | SnowBit | Sciencx | https://www.scien.cx/2022/01/09/how-to-make-http-requests-using-fetch/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.