-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathHttpClient.ts
36 lines (28 loc) · 1.12 KB
/
HttpClient.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
import { Formio } from "@tsed/react-formio";
export class HttpClient {
constructor(private host?: string) {}
get<T = any>(endpoint: string, data?: any, options?: any): Promise<T> {
return this.makeRequest("get", endpoint, data, options);
}
post<T = any>(endpoint: string, data?: any, options?: any): Promise<T> {
return this.makeRequest("post", endpoint, data, options);
}
put<T = any>(endpoint: string, data?: any, options?: any): Promise<T> {
return this.makeRequest("put", endpoint, data, options);
}
head<T = any>(endpoint: string, data?: any, options?: any): Promise<T> {
return this.makeRequest("head", endpoint, data, options);
}
delete<T = any>(endpoint: string, data?: any, options?: any): Promise<T> {
return this.makeRequest("delete", endpoint, data, options);
}
makeRequest<T = any>(method: string, endpoint: string, data?: any, options?: any): Promise<T> {
return Formio.makeStaticRequest(
endpoint[0] === "/" ? `${this.host || Formio.getApiUrl()}${endpoint}` : endpoint,
method,
data,
options
);
}
}
export const httpClient = new HttpClient();