Skip to content

Instantly share code, notes, and snippets.

@amenayach
Last active September 1, 2019 23:26
Show Gist options
  • Save amenayach/dc1739cda52941cabcc5317d659503ff to your computer and use it in GitHub Desktop.
Save amenayach/dc1739cda52941cabcc5317d659503ff to your computer and use it in GitHub Desktop.
function http(url, method, payload, callback) {
const options = {
method: method ? method : 'GET',
headers: {
"Content-Type": "application/json"
}
};
if(payload) {
options.body = JSON.stringify(payload);
}
fetch(url, options)
.then(res => res.json())
.then(data => {
if (callback) callback(data);
else console.log(data);
})
.catch(error => console.error(error));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment