Navi
Navi

Reputation: 1052

How to return an API response n times after calling it in python?

I have been using python 3x and made an API as below:

@app.route('/testapi', methods=['POST'])
def test_api():
    try:
        response = {'MSG': "Works"}
        return response
    except:
        return False

I have been calling this API from javascript, Once I call the /testapi , it should return the response n(eg:4) times with a time delay of 10 seconds. How can I achieve this solution?

Upvotes: 0

Views: 55

Answers (1)

charchit
charchit

Reputation: 1512

You can then use setInterval and clearInterval for this.

var x = 0;
var intervalID = setInterval(function () {

   // Your logic for calling api here

   if (++x === 4) { // call four times times
       window.clearInterval(intervalID);
   }
}, 10000);// 1 sec == 1000ms

Upvotes: 1

Related Questions