-
Notifications
You must be signed in to change notification settings - Fork 12
/
api.js
40 lines (32 loc) · 920 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
37
38
39
40
import axios from "axios";
class ApiService {
async get(url, config = {}) {
var base = process.env.VUE_APP_ROOT_API;
const response = await axios.get(`${base}${url}`, config);
if (response.error) {
return Promise.reject(
new Error(`Error GET ${url} : ${JSON.stringify(response)}`)
);
}
return response.data;
}
async post(url, data = {}, config = {}) {
config.headers ||
(config.headers = {
"Content-Type": "application/json"
});
var base = process.env.VUE_APP_ROOT_API;
const response = await axios.post(`${base}/${url}`, data, config);
if (response.error) {
return Promise.reject(
new Error(`Error POST ${url} : ${JSON.stringify(response)}`)
);
}
return response.data;
}
async apiState() {
const response = await this.get(`/state`);
return response;
}
}
export default new ApiService();