-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi-request.ts
More file actions
27 lines (24 loc) · 673 Bytes
/
api-request.ts
File metadata and controls
27 lines (24 loc) · 673 Bytes
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
import axios, { AxiosInstance } from 'axios'
import { CommonApiParamsInterface } from '~/interfaces/CommonApiParmsInterface'
export default class ApiRequest {
public client: AxiosInstance
constructor(baseUrl?: string) {
this.client = axios.create({
baseURL: baseUrl ?? process.env.apiHost,
responseType: 'json',
})
}
public async get<T>(
endpoint: string,
params?: CommonApiParamsInterface
): Promise<T> {
return await this.client
.get(endpoint, {
params,
})
.then((response) => {
// console.log('Api Client Request', { endpoint, params, response })
return response.data
})
}
}