Skip to content

Instantly share code, notes, and snippets.

@SanjeQi
Created August 20, 2020 15:46
Show Gist options
  • Save SanjeQi/2f94b0983852bc502f44a5615fe6b05c to your computer and use it in GitHub Desktop.
Save SanjeQi/2f94b0983852bc502f44a5615fe6b05c to your computer and use it in GitHub Desktop.
const data = { username: 'example' };
fetch('https://example.com/profile', {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment