Skip to content

Instantly share code, notes, and snippets.

@infantiablue
Last active April 28, 2021 06:15
Show Gist options
  • Save infantiablue/132b0f3144cf767e2a2dbf711cdb3d67 to your computer and use it in GitHub Desktop.
Save infantiablue/132b0f3144cf767e2a2dbf711cdb3d67 to your computer and use it in GitHub Desktop.
Fetch API Wrapper
const callAPI = async (url) => {
let response = await fetch(url, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
if (!response.ok) {
const message = `An error has occured: ${response.status}`;
throw new Error(message);
}
return response.json();
};
export default callAPI;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment