Setting timeout for HTTP-Request

I’m using the HTTP(S)-block in UI Builder to make a get request to a site. Is there a way to configure the timeout period after which an error is thrown if the site is not available?
Currently, this timeout period differs between Browsers and mobile/desktop.

Regards,

hello @Klaas_Klever

it is not possible with block, but it is possible with code, if it works for you we will give you instructions on how to do it

Sure. I’m happy to code …

Here is how it could look:

image

const req = Backendless.Request[method](url).setEncoding('utf8')

req.timeout = 30000

return req.send();

Here is the documentation about BackendlessRequest

And article about how to do the same with fetch - How to Timeout a fetch() Request

Also, as far as it is possible through the library that we use under the hood for Codeless, I’ve created an internal ticket to implement the same using Codeless, and we will notify you here when/if it will be implemented.

Regards, Dima.

Thank you. Much appreciated.

Hi @Dima ,
Your code shows Backendless.Request .... (is working well), whereas GitHub shows BackendlessRequest .... (without dot, not working in the browser).
Is there a difference when using on a browser client compared to an npm server?

Regards,

BackendlessRequest package is stored under Backendless namespace with the name Request

That means

BackendlessRequest === Backendless.Request

On the client you always have Backendless, so you could use Backendless.Request

As for the npm server, I’m not sure if I understand you correctly, but if you about Cloud Code - you could use Backendless.Request too.

Regards, Dima.

Hello @Klaas_Klever

We added a timeout property for the “Http/s” block.

Regards,
Inna

Thanks,
Will use it …