Communicating with external data source

Hello,

I think this question may have been asked before but I don’t seem to be able to find the answer. I have also looked at external content sample, but can’t see how it is done as I cant see any call details to external sources.

I want to access an external server (probably using GET) and send it a string and the server will be sending a reply back (in string). Does anybody know if this can be done and how?

Thanks

Hi,

this could be done with a simple fetch request. Something like this:

async function askServer() {
 const res= await fetch(yourserverurl).catch(e => {
  console.error(e); return null;
 };
 if(res== null) return;
 console.log(res.ok, res.status);
 const text = await res.text(); // alternatively: await res.json();
  console.log("Server responded with", text);
  return text;
}

See Using the Fetch API - Web APIs | MDN