1

Is it possible to make a GET/POST call to an external rest API and not wait for the response?

David
  • 239
  • 1
  • 2
  • 12

2 Answers2

-1

GatewayScript urlopen has a callback so you can't just "ignore" the callback I'd assume, at least I can't think of a way to do that.. The callback takes two params, error and response and if you don't give them you'll get an error.

urlopen.open('http://example.com/mydoc.json', function (error, response) {
});
Anders
  • 3,198
  • 1
  • 20
  • 43
  • Doesn't work, the request is still synchronous. – Vatev Mar 14 '23 at 15:28
  • I tested it, it still blocks the processing of the original request (the one that triggered the script), until the `urlopen` request is finished. It may be async in the context of the specific script, but it still blocks throughput. – Vatev Mar 17 '23 at 08:43
  • No, you can run multiple threads in GWS, there's no blocking, just as in node.js. GWS is a Node.js core, with a few things stripped out. – Anders Mar 18 '23 at 18:46
-2

Use an asynchronous call like fetch, await or promise like below:

fetch(myRequest)
.then(function(response) {
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return response.blob();
})
.then(function(response) {
  //retrieve your data her from the response object
});
Ezani
  • 535
  • 3
  • 18