Skip to content

Commit f753873

Browse files
authored
Merge pull request #282 from hyva-themes/281/GET-HTTP-support
#281 support GET HTTP request
2 parents 9b62b24 + 9cb4734 commit f753873

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/reactapp/src/api/sendRequest.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,29 @@ export default function sendRequest(
2020
queryParams = {},
2121
relativeUrl,
2222
responseType = 'json',
23-
additionalHeaders = {}
23+
additionalHeaders = {},
24+
isGetRequest = false
2425
) {
2526
const headers = {
2627
'Content-Type': 'application/json',
2728
Store: storeCode,
2829
...additionalHeaders,
2930
};
31+
const method = isGetRequest ? 'GET' : 'POST';
3032
const token = LocalStorage.getCustomerToken();
3133
const url = `${config.baseUrl}${relativeUrl || '/graphql'}`;
3234

3335
if (token) {
3436
headers.Authorization = `Bearer ${token}`;
3537
}
3638

37-
return fetch(url, {
38-
headers,
39-
method: 'POST',
40-
body: JSON.stringify({ ...queryParams }),
41-
})
39+
const fetchOptions = { headers, method };
40+
41+
if (!isGetRequest) {
42+
fetchOptions.body = JSON.stringify({ ...queryParams });
43+
}
44+
45+
return fetch(url, fetchOptions)
4246
.then((response) => {
4347
if (response.ok && responseType === RESPONSE_TEXT) {
4448
return response.text();

0 commit comments

Comments
 (0)