Reputation: 283
Can we get a continuous data from REST server using python for a single GET request. I am using flask for the moment.
@app.route('/', methods = ['GET'])
def hello_world():
while True:
return 'Hello World!'
This would return "Hello World!" once but I would want String to be sent continuous to the client till a server program is stopped or hardware stop(CTRL+C) is pressed. or even I would be happy to have the String or XML sent continuously for a given time.
Upvotes: 2
Views: 3748
Reputation: 4993
Yes, there is a way, but it is not as simple as GET. You have to build the backend python to work asynchronously and send updates without a request. The best way that I have seen is using socket.io:
And here is a tutorial that shows a way of promoting the character string data you are asking about:
It is kind of hard to give you a code snippet without more, as the phrase "Hello World" is static and you would not see changes, so it is not useful. But the second link shows you how to set it up to detect changes, confirm connections/disconnections and promote data from the server to the client.
If you get stuck again, edit the post with real code and real data.
Upvotes: 5