Skip to content

Commit 200f31b

Browse files
committed
wrapping-react-components: post added to IHttpClient
1 parent e4b4711 commit 200f31b

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

wrapping-react-components/src/wrappers/httpClient.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios, { AxiosError, AxiosInstance, AxiosResponse } from "axios";
22

33
interface IHttpClient {
44
get<TResponse>(url: string): Promise<TResponse>;
5+
post<TResponse>(url: string, data?: object): Promise<TResponse>;
56
}
67

78
class AxiosHttpClient implements IHttpClient {
@@ -11,7 +12,7 @@ class AxiosHttpClient implements IHttpClient {
1112
return this.instance ?? this.initAxiosClient();
1213
}
1314

14-
initAxiosClient() {
15+
private initAxiosClient() {
1516
return axios.create();
1617
}
1718

@@ -27,6 +28,19 @@ class AxiosHttpClient implements IHttpClient {
2728
});
2829
});
2930
}
31+
32+
post<TResponse>(url: string, data?: object): Promise<TResponse> {
33+
return new Promise<TResponse>((resolve, reject) => {
34+
this.axiosClient
35+
.post<TResponse, AxiosResponse<TResponse>>(url, data)
36+
.then((result) => {
37+
resolve(result.data);
38+
})
39+
.catch((error: Error | AxiosError) => {
40+
reject(error);
41+
});
42+
});
43+
}
3044
}
3145

3246
export const httpClient: IHttpClient = new AxiosHttpClient();

0 commit comments

Comments
 (0)