Reputation: 10336
On my server, I'm launching a process whose results I keep writing in the response. When I'm done, I send 200. Accessing the URL directly via a browser, I see the text display gradually, line by line as I send it from the server.
When doing Axios.get however (and as is normal given the function's name), I only get the bulk of text when Axios finally received 200. Is there any way, using Axios, to get & print the response in chunks, as it receives it from the server?
Axios.get(backendURL + "package/pios", {
headers: { Authorization: "Bearer " + myToken },
}).then((res) => {
//Doing something only when the response ends.
});
Upvotes: 2
Views: 485
Reputation: 825
If you want to stick to HTTP, the only solution I can think off is writing a chunk of the data, and also including some identifier in the response that will let you get the next part of the response, and then you basically keep sending API requests with the identifier you get in each previous response to get the next part. (I am not sure if this method has a name)
But I think the best solution would be to use WebSockets, then you can very simply send whatever you need whenever you like to your client.
Upvotes: 1