Multiple http/2 post requests - associate response with request #56
-
Greetings, I've written up some code like the example in https://github.com/HoneyryderChuck/httpx/blob/master/examples/post.rb Copied below here for your reference. The issue, I am encounter, is I am HTTP POSTing 20 requests each with a { "user_id" => user_id } to the same URL My question, is if the 5th response is "status: 400", how do I get back the request that I asked for, because I need the user_id (which didn't come back with the response) require "httpx"
require "json"
include HTTPX
URLS = %w[http://nghttp2.org/httpbin/post] * 102
$HTTPX_DEBUG = true
client = Session.new
requests = URLS.map { |url| client.build_request(:post, url, json: {"bang" => "bang"}) }
responses = client.request(*requests)
responses.each do |res|
puts "status: #{res.status}"
puts "headers: #{res.headers}"
puts "body: #{JSON.parse(res.body.to_s)}"
end
# puts responses.map(&:status) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @danlo , Responses come in the same order as requests, so the 5th response corresponds to the 5th request. |
Beta Was this translation helpful? Give feedback.
Hi @danlo ,
Responses come in the same order as requests, so the 5th response corresponds to the 5th request.