This repository was archived by the owner on Dec 9, 2021. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHttpUtility.ts
56 lines (44 loc) · 1.47 KB
/
HttpUtility.ts
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
48
49
50
51
52
53
54
55
56
importaxios,{AxiosResponse}from'axios';
importRequestMethodEnumfrom'../constants/RequestMethodEnum';
// http://httpstat.us
exportdefaultclassHttpUtility{
publicasyncget(endpoint: string): Promise<AxiosResponse<any>>{
constrequest=newRequest(endpoint,{
method: RequestMethodEnum.Get,
});
returnthis._fetch(request);
}
// TODO: finish setting up
publicasyncpost(endpoint: string): Promise<AxiosResponse<any>>{
constrequest=newRequest(endpoint,{
method: RequestMethodEnum.Post,
});
returnthis._fetch(request);
}
// TODO: finish setting up
publicasyncput(endpoint: string): Promise<AxiosResponse<any>>{
constrequest=newRequest(endpoint,{
method: RequestMethodEnum.Put,
});
returnthis._fetch(request);
}
// TODO: finish setting up
publicasyncdelete(endpoint: string): Promise<AxiosResponse<any>>{
constrequest=newRequest(endpoint,{
method: RequestMethodEnum.Delete,
});
returnthis._fetch(request);
}
privateasync_fetch(request: Request,init?: any): Promise<AxiosResponse<any>>{
try{
returnawaitaxios({
data: init,
method: request.method,
url: request.url,
});
}catch(error){
console.error(`error`,error);
returnerror;
}
}
}