Skip to content

Instantly share code, notes, and snippets.


LukeSmetham/fetch.js Secret

Created Sep 24, 2019
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 = {
method: method.toUpperCase(),
baseURL: `${process.env.REACT_APP_API_ENDPOINT}v1`,
url: path,
data: data || {},
params: params || {},
headers: {
'Content-Type': 'application/json',
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.