Created
January 17, 2019 10:14
-
-
Save romannmk/0471bdb6e2c0b9858cc0ef624cc54141 to your computer and use it in GitHub Desktop.
call to api function
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
export default async (method, url, payload) => { | |
try { | |
const config = { | |
...(method !== 'GET' && { body: JSON.stringify(payload) }), | |
method: method, | |
headers: { | |
'Content-Type': 'application/json', | |
...(token && { Bearer: `token` }) | |
} | |
}; | |
const res = await fetch(`${url}`, config); | |
const data = await res.json(); | |
if (!res.ok) throw data; | |
return data; | |
} catch (error) { | |
throw error; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment