Last active
November 6, 2019 12:30
-
-
Save daliborgogic/3ff586e0250a8ede3827ff1f7bd804c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
async function foo (method, url, body) { | |
if (!url) throw new Error() | |
let config = { | |
headers: { accept: 'application/json' } | |
} | |
if (method && body) { | |
config.body = JSON.stringify(body) | |
config.method = method | |
} | |
const res = await fetch(url, { config }) | |
if (!res.ok) throw new Error(res) | |
return res.json() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment