-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
36 lines (32 loc) · 877 Bytes
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import axios from 'axios';
// here we are accepting baseURL also because our base url is different in most cases
const createInstance = (baseURL) => {
return axios.create({
baseURL,
headers: {
'Content-Type': 'application/json'
}
});
};
const get = async (url, config = {}) => {
try {
const response = await createInstance(config.baseURL).get(url, config);
return response.data;
} catch (error) {
console.error('Error fetching data:', error);
throw error;
}
};
const post = async (url, data = {}, config = {}) => {
try {
const response = await createInstance(config.baseURL).post(url, data, config);
return response.data;
} catch (error) {
console.error('Error posting data:', error);
throw error;
}
};
export default {
get,
post
};