Call 3rd party API, await the result without blocking main thread

Hi everyone!
I want to create an endpoint that calls a 3rd party API, gets the data, does some quick modification(doesn’t really matter what) and returns them as JSON.
The problem is that if the user decides to leave the current URL and sends a new request for a different view to render a new template, while the data are being downloaded, the new template doesn’t get loaded.
From my understanding this happens because I am blocking the main thread when calling the API, so when the new request comes through, Django cannot respond to that since it’s still processing the initial request to the external API.
I did some research about this and Celery seems like a common solution to this, however I don’t think it solves my exact problem since the goal is not to start a background task and forget about it, but rather get the results and send them to the client.

Is there another solution like Celery or is my approach wrong here?

That’s going to depend in part on how you’re running your server. If you’re using a proper server, one request is not going to block other requests from executing.

When I run it locally with runserver it blocks it. Maybe I should try to set up a proper server locally at first to see what’s going to happen.
Also another question is when the user sends a request to a different URL(and a new view is called) is there any way to save the data that are longer needed in the previous view?

What operating system are you using? (It doesn’t block in Linux.)

Is this second url request being issued by the JavaScript running in the same page? If so, then that would be the single thread that is blocking this.

No. You’ve abandoned that request.