Skip to content

Instantly share code, notes, and snippets.

@tamalchowdhury
Created January 28, 2022 15:29
Show Gist options
  • Save tamalchowdhury/145f723a94d0406e20c32f802b878ba8 to your computer and use it in GitHub Desktop.
Save tamalchowdhury/145f723a94d0406e20c32f802b878ba8 to your computer and use it in GitHub Desktop.
// 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