0

My backend takes time to fetch the data but till then , I have to wait for it to respond. Instead what I want is to show a response and when the data in the backend is processed , the server displays it. I am trying to do this using RestPlus(flask) and not able to do this.

I have created an api and i have called "api.response" method as soon as the url is called but it is not giving the server response.


@api.route('/hello')
class Hello(Resource):
    @api.response(code=200,description='hello world')
    def get(self):
        sleep(10)
        return 'Hello X'
jack
  • 101
  • 1
  • 9
  • You can't do exactly what you ask for. You'll have to handle this from the frontend. There are a few alternatives, though. For example, you could cache the results for faster subsequent requests (see flask-caching). Another thing that is kinda what you ask for would be to do the job in the background. For example, as soon as you get a request, trigger a task (see Celery) and send an immediate response to the client. Then, query the task status from the front until it's done. – AArias Jun 05 '19 at 12:17
  • Okay. I will try your solutions.Thanks:) – jack Jun 05 '19 at 12:22

0 Answers0