|
Lines 47-73
class HttpClient {
Link Here
|
| 47 |
} |
47 |
} |
| 48 |
|
48 |
|
| 49 |
post(params = {}) { |
49 |
post(params = {}) { |
|
|
50 |
const body = params.body |
| 51 |
? typeof str === "string" |
| 52 |
? params.body |
| 53 |
: JSON.stringify(params.body) |
| 54 |
: undefined; |
| 50 |
return this._fetchJSON(params.endpoint, params.headers, { |
55 |
return this._fetchJSON(params.endpoint, params.headers, { |
| 51 |
...params.options, |
56 |
...params.options, |
| 52 |
body: params.body ? JSON.stringify(params.body) : undefined, |
57 |
body, |
| 53 |
method: "POST", |
58 |
method: "POST", |
| 54 |
}); |
59 |
}); |
| 55 |
} |
60 |
} |
| 56 |
|
61 |
|
| 57 |
put(params = {}) { |
62 |
put(params = {}) { |
|
|
63 |
const body = params.body |
| 64 |
? typeof str === "string" |
| 65 |
? params.body |
| 66 |
: JSON.stringify(params.body) |
| 67 |
: undefined; |
| 58 |
return this._fetchJSON(params.endpoint, params.headers, { |
68 |
return this._fetchJSON(params.endpoint, params.headers, { |
| 59 |
...params.options, |
69 |
...params.options, |
| 60 |
body: params.body ? JSON.stringify(params.body) : undefined, |
70 |
body, |
| 61 |
method: "PUT", |
71 |
method: "PUT", |
| 62 |
}); |
72 |
}); |
| 63 |
} |
73 |
} |
| 64 |
|
74 |
|
| 65 |
delete(params = {}) { |
75 |
delete(params = {}) { |
| 66 |
return this._fetchJSON(params.endpoint, params.headers, { |
76 |
return this._fetchJSON( |
| 67 |
parseResponse: false, |
77 |
params.endpoint, |
| 68 |
...params.options, |
78 |
params.headers, |
| 69 |
method: "DELETE", |
79 |
{ |
| 70 |
}, true); |
80 |
parseResponse: false, |
|
|
81 |
...params.options, |
| 82 |
method: "DELETE", |
| 83 |
}, |
| 84 |
true |
| 85 |
); |
| 71 |
} |
86 |
} |
| 72 |
|
87 |
|
| 73 |
count(params = {}) { |
88 |
count(params = {}) { |
|
Lines 84-89
class HttpClient {
Link Here
|
| 84 |
); |
99 |
); |
| 85 |
} |
100 |
} |
| 86 |
|
101 |
|
|
|
102 |
patch(params = {}) { |
| 103 |
const body = params.body |
| 104 |
? typeof str === "string" |
| 105 |
? params.body |
| 106 |
: JSON.stringify(params.body) |
| 107 |
: undefined; |
| 108 |
return this._fetchJSON(params.endpoint, params.headers, { |
| 109 |
...params.options, |
| 110 |
body, |
| 111 |
method: "PATCH", |
| 112 |
}); |
| 113 |
} |
| 114 |
|
| 87 |
checkError(response, return_response = 0) { |
115 |
checkError(response, return_response = 0) { |
| 88 |
if (response.status >= 200 && response.status <= 299) { |
116 |
if (response.status >= 200 && response.status <= 299) { |
| 89 |
return return_response ? response : response.json(); |
117 |
return return_response ? response : response.json(); |
| 90 |
- |
|
|