Question 21
Consider the below flask app, and an HTML file named “index.html”.
app.py:
from flask import Flaskimport time
app = Flask(__name__)
@app.route("/endpoint1")def method1(): time.sleep(20) return "Endpoint 1 Accessed", 200, {'Access-Control-Allow-Origin' :'*'}
@app.route("/endpoint2")def method2(): time.sleep(30) return "Endpoint 2 Accessed", 200, {'Access-Control-Allow-Origin' :'*'}
if __name__ == "__main__": app.run(threaded = False)index.html:
<div> Hello World !!
<script> const data1 = fetch("http://127.0.0.1:5000/endpoint1").then(res =>res.json()).then(data => console.log(data))
const data2 = fetch("http://127.0.0.1:5000/endpoint2").then(res =>res.json()).then(data => console.log(data)) </script></div>Suppose you open the “index.html” in a browser. What will be the approximate time taken by the second fetch call (i.e., "http://127.0.0.1:5000/endpoint2") to complete and log the data on the console?
20 seconds
30 seconds
10 seconds
50 seconds