Skip to content

Commit

Permalink
Merge pull request #282 from hyva-themes/281/GET-HTTP-support
Browse files Browse the repository at this point in the history
#281 support GET HTTP request
  • Loading branch information
wigman committed Apr 10, 2022
2 parents 9b62b24 + 9cb4734 commit f753873
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/reactapp/src/api/sendRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,29 @@ export default function sendRequest(
queryParams = {},
relativeUrl,
responseType = 'json',
additionalHeaders = {}
additionalHeaders = {},
isGetRequest = false
) {
const headers = {
'Content-Type': 'application/json',
Store: storeCode,
...additionalHeaders,
};
const method = isGetRequest ? 'GET' : 'POST';
const token = LocalStorage.getCustomerToken();
const url = `${config.baseUrl}${relativeUrl || '/graphql'}`;

if (token) {
headers.Authorization = `Bearer ${token}`;
}

return fetch(url, {
headers,
method: 'POST',
body: JSON.stringify({ ...queryParams }),
})
const fetchOptions = { headers, method };

if (!isGetRequest) {
fetchOptions.body = JSON.stringify({ ...queryParams });
}

return fetch(url, fetchOptions)
.then((response) => {
if (response.ok && responseType === RESPONSE_TEXT) {
return response.text();
Expand Down

0 comments on commit f753873

Please sign in to comment.