Ruby library for creating multiple HTTP requests at once

I am looking for an alternative Ruby HTTP library that makes multiple HTTP calls at the same time and works better than the main Net :: HTTP library.

+4
source share
4 answers

You are probably looking for typhoid.

Typhoeus launches HTTP requests in parallel, pure encapsulation of processing logic

https://github.com/typhoeus/typhoeus

+3
source

Why do you need a parallelism network library descriptor? This is exactly what themes are for.

require "open-uri" fetcher = lambda do |uri| puts "Started fetching #{uri}" puts open(uri).read puts "Stopped fetching #{uri}" end thread1 = Thread.new("http://localhost:9292", &fetcher) thread2 = Thread.new("http://localhost:9293", &fetcher) thread1.join thread2.join 

Also, I don't understand what you mean by "works better." Core libraries are usually good enough to be at the core. Have problems with Net :: HTTP?

+3
source

You can use Parallel gem, it should work with any Ruby HTTP library.

+1
source

Not sure if it works better than Typhoeus, but you can use Eventmacheine + em-http-request. An example of sending multiple requests.

 require 'eventmachine' require 'em-http' EventMachine.run { multi = EventMachine::MultiRequest.new reqs = [ 'http://google.com/', 'http://google.ca:81/' ] reqs.each_with_index do |url, idx| http = EventMachine::HttpRequest.new(url, :connect_timeout => 1) req = http.get multi.add idx, req end multi.callback do p multi.responses[:callback].size p multi.responses[:errback].size EventMachine.stop end } 

https://github.com/igrigorik/em-http-request

0
source

Source: https://habr.com/ru/post/1379870/


All Articles