0

Suppose, I have sent a post request from react to Django rest API and that request is time taking. I want to get how many percentages it has been processed and send to the frontend without sending the real response?

1 Answer 1

1

There are two broad ways to approach this.

  1. (which I would recommend to start with): Break the request up. The initial request doesn't start the work, it sends a message to an async task queue (such as Celery) to do the work. The response to the initial request is the ID of the Celery task that was spawned. The frontend now can use that request ID to poll the backend periodically to check if the task is finished and grab the results when they are ready.

  2. Websockets, wherein the connection to the backend is kept open across many requests, and either side can initiate sending data. I wouldn't recommend this to start with, since its not really how Django is built, but with a higher level of investment it will give an even smoother experience.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Paul Becotte, I have to use it with image uploading case. will it be good practice to go with 1 in production?
If its just image uploading, the browser has already sent the image by the time django fires up the view, and the browser knows how to show that. If you're talking about stuff like "copy the image to s3 and make a thumbnail", then yes, that is how I would recommend doing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.