Skip to content

Instantly share code, notes, and snippets.



Last active Nov 6, 2019
What would you like to do?
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
You can’t perform that action at this time.