Similar to this question I am trying to call a Java+Kotlin Spring Boot REST service from JS.
However instead of XMLHttpRequest, I use fetch function:
function sendGetCountriesRequestToBackend(port) {
const endpoint = "/countries";
const url = 'http://localhost:' + port + endpoint;
const arguments = {
method: "GET",
mode: "no-cors",
cache: "no-cache",
credentials: "omit",
headers: {
"Content-Type": "application/json"
},
redirect: "follow",
referrer: "no-referrer"
};
fetch(url, arguments)
.then(response => response.json())
.then(getOnBackendFulfilled())
.then(null, getOnBackendRejected());
}
getOnBackendFulfilled() and getOnBackendRejected() are defined.
After calling sendGetCountriesRequestToBackend() I get SyntaxError: Unexpected end of input
I suppose there's something wrong with arguments for fetch functions. Any ideas how to change them?