Is there a way to delay the response time?

Lets say i have a backend which respond in 30 ms.For the testing purpose i need a backend which respond in different time limits(60ms,90ms,1s...).Does apigee has any policy which will delay the response time?

0 8 3,394
8 REPLIES 8

You can use Javascript policy and add code for time delay in that before hitting your target.

Thanks @Sonali.

I guess that Apigee doesn't support setTimeout function.Is there any other method to do the same.It would be helpful if you share the code snippet for the time delay in js Apigee.

Yes you are right apigee does not support setTimeout function.

One of possible way is doing that using node script means calling your back-end through node.

This might be helpful to u:

https://community.apigee.com/questions/9385/setting-up-delay-for-retrying-backend.html

If I wanted my API Proxy to delay, I would do it with this Java callout.

Other suggestions, like use a JavaScript callout, or use nodejs... won't work in the current Apigee.

Not applicable

To add more to @Sonali's answer on Node.js. Another alternative to introduce delays is to use a library such as Nock. Here's an example of how to do it:

nock('http://my.server.com')
  .get('/')
  .delay(2000) // 2 seconds
  .reply(200, '<html></html>')

Also, here's an article with a tutorial on how to build an API Proxy with Node.js and Nock. https://community.apigee.com/articles/2354/how-to-build-an-nodejs-api-proxy-with-mocks.html

Hope it helps!

Node JS that sleep/waits N number of milliseconds

This is how I would do it. With this Java callout.

Other suggestions, like use a JavaScript callout, or use nodejs... won't work in the current Apigee.