-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.js
47 lines (39 loc) · 1.19 KB
/
request.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
41
42
43
44
45
46
47
import axios from 'axios';
import {buildQueryParams} from "./commonUtility";
class Service {
constructor() {
let service = axios.create({
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
baseURL:process.env.REACT_APP_BASE_URL,
responseType:'json'
});
service.interceptors.response.use(this.handleSuccess, this.handleError);
this.service = service;
}
handleSuccess = (response) => {
return response.data;
};
handleError = (error) => {
return Promise.reject(error)
};
get(path, queryParams) {
return this.service.get(`${path}${buildQueryParams(queryParams)}`);
}
post(path, payload) {
return this.service({method: 'POST', url: path, data: payload});
}
patch(path, payload) {
return this.service({method: 'PATCH', url: path, data: payload});
}
put(path, payload) {
return this.service({method: 'PUT', url: path, data: payload});
}
delete(path) {
return this.service({method: 'DELETE', url: path});
}
}
const request = new Service();
export default request;