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
- Follow me on Twitter - @codewithsnowbit
- Subscribe me on YouTube - Code With SnowBit
This content originally appeared on DEV Community and was authored by SnowBit
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
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/
" » 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/
HARVARDSnowBit | 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/>
VANCOUVERSnowBit | 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.