Skip to content

Instantly share code, notes, and snippets.

@LukeSmetham LukeSmetham/fetch.js Secret
Created Sep 24, 2019

Embed
What would you like to do?
import axios from 'axios';
const fetch = (method, path, data, params, headers, cancelToken) => {
if (!method) throw new Error('Method is a required field.');
if (!path) throw new Error('Path is a required field.');
const options = {
cancelToken,
method: method.toUpperCase(),
baseURL: `${process.env.REACT_APP_API_ENDPOINT}v1`,
url: path,
data: data || {},
params: params || {},
headers: {
'Content-Type': 'application/json',
...headers,
},
};
return axios(options);
};
const cancelToken = () => axios.CancelToken.source();
export default fetch;
export { cancelToken };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.