Skip to content

Instantly share code, notes, and snippets.

@amosuro
Created November 5, 2018 12:32
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 amosuro/e4286b1d0267daa6bc471b9cd788cbdc to your computer and use it in GitHub Desktop.
Save amosuro/e4286b1d0267daa6bc471b9cd788cbdc to your computer and use it in GitHub Desktop.
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