Last active
September 1, 2019 23:26
-
-
Save amenayach/dc1739cda52941cabcc5317d659503ff 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
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