Skip to content

Instantly share code, notes, and snippets.

@desaijay315
Last active May 24, 2021 05:42
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 desaijay315/6983d2a393cbcf51baa1572341cb0c6e to your computer and use it in GitHub Desktop.
Save desaijay315/6983d2a393cbcf51baa1572341cb0c6e to your computer and use it in GitHub Desktop.
function client(endpoint, customConfig = {}) {
const config = {
method: 'GET',
...customConfig,
}
return window
.fetch(`${process.env.REACT_APP_API_URL}/${endpoint}`, config)
.then(async response => {
const data = await response.json()
if (response.ok) {
return data
} else {
return Promise.reject(data)
}
})
}
export {client}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment