Skip to content

Instantly share code, notes, and snippets.

@Ormadont
Created June 13, 2018 18:43
Show Gist options
  • Save Ormadont/1eb881eb823b95c7e9f291a1f014ba28 to your computer and use it in GitHub Desktop.
Save Ormadont/1eb881eb823b95c7e9f291a1f014ba28 to your computer and use it in GitHub Desktop.
// boilerplate code necessary to create a POST request using the fetch()
//The boilerplate code for an AJAX POST request using fetch.
fetch('https://api-to-call.com/endpoint', {
method: 'POST',
body: JSON.stringify({id: '200'})
}).then( response => {
if (response.ok) {
return response.json();
}
throw new Error('Request failed!');
}, networkError => {
console.log(networkError.message);
}).then( jsonResponse => {
return jsonResponse;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment