How to set a time limit on the HttpClient.send in JavaScript in Apigee Edge

How to set a time limit on the HttpClient.send in JavaScript in Apigee Edge

I don’t want to add timelimit in JS policy.

I have to set timelimit in JS only. Below code is not working.

var authRequest = new Request(context.getVariable(‘url’), “POST”, header, formBody(payload));

var response = httpClient.send(authRequest, response => {
fetchAuth(response);
}, 1000); //timeout in 1 sec

As setTimeout, Promise, callback, http, setInterval are not working. How can i set timeout limit in API call? Please help.

Can we use ServiceCallout Policy if yes then how, because we don’t have to call target end point directly, as needs to call OAuth from JS where i have to set timeout.

1 Like

Hi @Garima96 , thanks for your question, we’ve noticed it hasn’t received an answer yet. We encourage other community members to take a look and share any insights they may have. We’ll also keep an eye on the conversation to ensure you get a response :blush:

In the meantime, feel free to check out our upcoming events and articles - you might find related resources helpful.

Ty for your patience!!!

Hi @AlexET ,

I’m also experiencing this issue, which is significantly impacting our ability to support customers using Apigee in conjunction with our software. This limitation has surfaced multiple times in community discussions over the years, but it’s unclear if or when native timeout support for httpClient.send() in JavaScript might be implemented.

References to similar requests and discussions:

Setting HTTP connection timeout httpClient in JS

Default timeout for httpClient calls made through JavaScript policies

How to set a time limit on the httpClient.send() in JavaScript (This issue)

Is there any update on whether native support for this feature is planned or under consideration? This would be immensely helpful for those of us needing direct control over request timeouts within JavaScript policies.

Thank you for any guidance you can provide.

Hello Garima, Saad:

would you consider using asynchronous i.e. fire-and-forget invocation ?

There is an example in the response:

here: https://www.googlecloudcommunity.com/gc/Apigee/Asynchronous-calls-using-service-callout-policy/td-p/5788

It might not exactly be useful if you want to enforce a strict timeout, but will help with a range of related use cases.

Best regards