@tatil/server-api 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/tatilsepeti.js +30 -6
package/package.json
CHANGED
package/src/utils/tatilsepeti.js
CHANGED
|
@@ -12,18 +12,42 @@ class TatilsepetiApi {
|
|
|
12
12
|
this.instance = axios.create({
|
|
13
13
|
baseURL: API_URL,
|
|
14
14
|
});
|
|
15
|
+
|
|
15
16
|
this.logger = RequestLogger();
|
|
16
17
|
this.defaultHeaders = {
|
|
17
18
|
'Content-Type': 'application/json',
|
|
18
19
|
};
|
|
20
|
+
|
|
21
|
+
this.attachInterceptors();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
attachInterceptors() {
|
|
25
|
+
this.instance.interceptors.response.use(
|
|
26
|
+
(response) => {
|
|
27
|
+
console.log('[API RESPONSE]', {
|
|
28
|
+
url: response.config.url,
|
|
29
|
+
status: response.status,
|
|
30
|
+
data: response.data,
|
|
31
|
+
});
|
|
32
|
+
return response;
|
|
33
|
+
},
|
|
34
|
+
(error) => {
|
|
35
|
+
console.error('[API RESPONSE ERROR]', {
|
|
36
|
+
url: error.config?.url,
|
|
37
|
+
status: error.response?.status,
|
|
38
|
+
data: error.response?.data,
|
|
39
|
+
});
|
|
40
|
+
return Promise.reject(error);
|
|
41
|
+
}
|
|
42
|
+
);
|
|
19
43
|
}
|
|
20
44
|
|
|
21
45
|
joinEndpoint(endpoint) {
|
|
22
46
|
return endpoint.join('/');
|
|
23
47
|
}
|
|
24
48
|
|
|
25
|
-
fullEndpoint(endpoint) {
|
|
26
|
-
return `${this.baseURL}/api
|
|
49
|
+
fullEndpoint(endpoint, version = 'v1') {
|
|
50
|
+
return `${this.baseURL}/api/${version}/${this.joinEndpoint(endpoint)}`;
|
|
27
51
|
}
|
|
28
52
|
|
|
29
53
|
buildUrl(endpoint) {
|
|
@@ -89,10 +113,10 @@ class TatilsepetiApi {
|
|
|
89
113
|
);
|
|
90
114
|
}
|
|
91
115
|
|
|
92
|
-
async get(endpoint, params = {}) {
|
|
116
|
+
async get(endpoint, params = {}, version = 'v1') {
|
|
93
117
|
const endpointPath = this.getEndpointPath(endpoint);
|
|
94
118
|
const logId = this.logger.start(endpointPath, 'GET');
|
|
95
|
-
const url = this.buildUrl(endpoint);
|
|
119
|
+
const url = this.buildUrl(endpoint, version);
|
|
96
120
|
|
|
97
121
|
const response = await this.instance.get(url, {
|
|
98
122
|
params,
|
|
@@ -128,10 +152,10 @@ class TatilsepetiApi {
|
|
|
128
152
|
return data;
|
|
129
153
|
}
|
|
130
154
|
|
|
131
|
-
async post(endpoint, body = {}) {
|
|
155
|
+
async post(endpoint, body = {}, version = 'v1') {
|
|
132
156
|
const endpointPath = this.getEndpointPath(endpoint);
|
|
133
157
|
const logId = this.logger.start(endpointPath, 'POST');
|
|
134
|
-
const url = this.buildUrl(endpoint);
|
|
158
|
+
const url = this.buildUrl(endpoint, version);
|
|
135
159
|
|
|
136
160
|
const response = await this.instance.post(url, body, {
|
|
137
161
|
headers: await this.getAuthHeaders(),
|