Created
November 5, 2018 12:32
-
-
Save amosuro/e4286b1d0267daa6bc471b9cd788cbdc 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
const post = async (data) => { | |
const { url } = data; | |
delete data.url; | |
const params = { | |
method: 'POST', | |
body: JSON.stringify(data), | |
headers: { | |
'Content-Type': 'application/json', | |
'Accept': 'application/json' | |
} | |
}; | |
const response = await fetch(url, params); | |
if (response.status < 200 && response.status >= 300) { | |
const res = await response.json(); | |
throw new Error(res); | |
} | |
return response.json(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment