Bidirectional Concurrent Streaming in HTTP/2 #71
Unanswered
AbanoubGhadban
asked this question in
Q&A
Replies: 1 comment 6 replies
-
Hi @AbanoubGhadban , I believe it's possible, at the very least with the stream plugin. The this can probably work without plugins, as long as you provide the corresponding custom functionality in a plugin. FWIW this is an example how you could send the body in chunks (it may require adjustments): req_body = form_entries.lazy.map do |entry|
entry = JSON.dump(entry) + '\n'
sleep(1)
puts "Sent form entry: #{entry.strip}"
entry
end
stream_session = HTTPX.plugin(:stream)
response = .post("https://localhost:3000/ndjson", headers: { "content-type" => "application/nd+json" }, body: req_body, stream: true)
response.each do |chunk|
puts "chunk: #{chunk}"
end |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to achieve bidirectional streaming in an HTTP/2 POST request using HTTPx?
Here is an example scenario I am working on:
This code sends chunks of NDJSON to an echo server that returns the processed chunk, formatted as
{"processed" => <message>}
.However, the responses are only printed after the entire request body is sent. The output looks like this:
What I want to achieve is immediate processing of each chunk, with output like this:
Is there a way to achieve this behavior using HTTPx or any of its plugins? If not, are there alternative approaches within HTTPx or recommendations for other libraries to enable such bidirectional streaming in HTTP/2?
FYI, the following nodejs code worked as expected, so I think the problem is not at the server
Its output is
Beta Was this translation helpful? Give feedback.
All reactions