Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active November 6, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daliborgogic/3ff586e0250a8ede3827ff1f7bd804c7 to your computer and use it in GitHub Desktop.
Save daliborgogic/3ff586e0250a8ede3827ff1f7bd804c7 to your computer and use it in GitHub Desktop.
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