Lines 1-12
Link Here
|
1 |
class HttpClient { |
1 |
class HttpClient { |
2 |
constructor(options = {}) { |
2 |
constructor(options = {}) { |
3 |
this._baseURL = options.baseURL || ""; |
3 |
this._baseURL = options.baseURL || ""; |
|
|
4 |
this._headers = options.headers || { |
5 |
"Content-Type": "application/json;charset=utf-8", |
6 |
}; |
4 |
} |
7 |
} |
5 |
|
8 |
|
6 |
async _fetchJSON(endpoint, headers = {}, options = {}) { |
9 |
async _fetchJSON(endpoint, headers = {}, options = {}) { |
7 |
const res = await fetch(this._baseURL + endpoint, { |
10 |
const res = await fetch(this._baseURL + endpoint, { |
8 |
...options, |
11 |
...options, |
9 |
headers: headers, |
12 |
headers: { ...this._headers, ...headers }, |
10 |
}); |
13 |
}); |
11 |
|
14 |
|
12 |
if (!res.ok) throw new Error(res.statusText); |
15 |
if (!res.ok) throw new Error(res.statusText); |
Lines 18-24
class HttpClient {
Link Here
|
18 |
} |
21 |
} |
19 |
|
22 |
|
20 |
get(params = {}) { |
23 |
get(params = {}) { |
21 |
console.log(params); |
|
|
22 |
return this._fetchJSON(params.endpoint, params.headers, { |
24 |
return this._fetchJSON(params.endpoint, params.headers, { |
23 |
...params.options, |
25 |
...params.options, |
24 |
method: "GET", |
26 |
method: "GET", |
Lines 50-59
class HttpClient {
Link Here
|
50 |
} |
52 |
} |
51 |
|
53 |
|
52 |
//TODO: Implement count method |
54 |
//TODO: Implement count method |
53 |
|
|
|
54 |
getDefaultJSONPayloadHeader() { |
55 |
return { "Content-Type": "application/json;charset=utf-8" }; |
56 |
} |
57 |
} |
55 |
} |
58 |
|
56 |
|
59 |
export default HttpClient; |
57 |
export default HttpClient; |
60 |
- |
|
|