1
There is some way to send data over Http, but instead of all the information at once, send one part at a time?
For example: I make an HTTP request to GET /produtos
. This will return all my products (assuming I didn’t set a limit). If I have 500 products, this will make the request time-consuming, until all products are processed-- and I can only process the information of the first product in the client when the server finishes processing the last.
I wonder if, following this example, there is some way for the server to send one product at a time, in a kind of "streaming"-- so client and server would be working simultaneously, rather than one at a time.
(The client code I know is one, in Javascript. The server code, for me, is irrelevant, but I would like to know at least what technique is used for me to research. If I can not implement on my server, I open a new question, because this should be only about the technique used and the client code)
Clarifying: I will be using Ajax, so yes, my request will be asynchronous. What I want is to get the server and the client to work at the same time, rather than the server doing all its work before the client starts working.
In a simple request, the workflow would be basically this:
Cliente faz requisição ->
Servidor processa 500 produtos e envia ao cliente ->
Cliente processa os 500 produtos
And my intention is to do this:
Cliente faz requisição ->
Servidor processa um produto e envia ao cliente (e repete o processo até que não hajam mais produtos) ->
Cliente processa um produto assim que o recebe (e aguarda por mais até que acabem)
You could work with a queue that would trigger AJAX requests as long as there are items to be sent. The triggering of new requests, from the second, could even be associated with the click.
– Bruno Augusto
@Brunoaugusto I thought about it, but I thought it would be very funny. So I asked here, to find out if there is a more "right" way. But if I don’t, I’m gonna use that.
– André Leria
I don’t think it’s a scam, but if you prefer you can also apply the concept of paging by sending bigger and bigger offsets every time you click the button, for example.
– Bruno Augusto
@Brunoaugusto The idea is very good, but it does not involve a "flow" as I specified in the question. I’m not saying the idea is invalid, but pagination and flow are different concepts.
– André Leria