Created
January 28, 2022 15:29
-
-
Save tamalchowdhury/145f723a94d0406e20c32f802b878ba8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fetch API | |
// Fetch is a built in browser API built into JavaScript. | |
fetch('https://example.com/api/') | |
.then(res => res.json()) | |
.then(data => data) | |
.catch(err => err) | |
fetch('https://example.com/api/') | |
.then(res => res.json()) | |
.then(data => { | |
// Do something with data | |
}) | |
.catch(error => { | |
// Handle the error | |
}) | |
fetch('https://example.com/api/', {method: 'POST', data: JSON.stringify(data)}) | |
.then(res => res.json()) | |
.then(data => data) | |
.catch(err => err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment