Fastapi asynchronous response (bg tasks)

Viewed 17

I am using fastapi for the first time in a project. I receive information from an html form and return a HTMLResponse object to indicate that the program is running in the background (thanks to the BackgroundTask object). Is there a way to return another HTML file and to make my browser switch to that once the background task is over?

Sorry if I use the wrong terminology, but I am no expert. Cheers

1 Answers



So what you need to do here is implement websockets. After your task is finished you can have to send a message on the websockets intimidating that the task has finished.
Think of it like a notification service.

You can find some documentation here
You will have to connect to the websocket from your frontend as well.

Do you research on this, I'm sure you will find a lot of documentation and articles on this idea.

Related