-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-client.ts
More file actions
40 lines (34 loc) · 804 Bytes
/
Copy pathapi-client.ts
File metadata and controls
40 lines (34 loc) · 804 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
28
29
30
31
32
33
34
35
36
37
38
39
40
import axios, { AxiosInstance } from 'axios';
import { getConfig } from './config';
interface RequestParams {
method: string;
url: string;
data?: any;
}
class APIClient {
private client: AxiosInstance;
constructor() {
const { baseURL, apiKey } = getConfig();
if (!apiKey) {
throw new Error(
'API key is not set. Please set the API key before using the SDK.'
);
}
this.client = axios.create({
baseURL: baseURL,
headers: {
'Layerup-API-Key': apiKey,
'Content-Type': 'application/json',
},
});
}
async request({ method, url, data = {} }: RequestParams): Promise<any> {
const response = await this.client({
method,
url,
data,
});
return response.data;
}
}
export default APIClient;