FunnelHttp

Perform HTTP requests in parallel

Gem Version build

Requirements

  • Ruby
  • Go

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add funnel_http

If bundler is not being used to manage dependencies, install the gem by executing:

gem install funnel_http

Usage

Use FunnelHttp::Client#perform

require "funnel_http"

client = FunnelHttp::Client.new

requests = [
  {
    method: :get,
    uri: "https://example.com/api/user/1",
  },

  # with request header
  { 
    method: :get, 
    uri: "https://example.com/api/user/2", 
    header: {
      "Authorization" => "Bearer xxxxxxxx",
      "X-Multiple-Values" => ["1st value", "2nd value"],
    },
  },
]

responses = client.perform(requests)
# => [
#   { status_code: 200, body: "Response of /api/user/1", header: { "Content-Type" => ["text/plain;charset=utf-8"]} }
#   { status_code: 200, body: "Response of /api/user/2", header: { "Content-Type" => ["text/plain;charset=utf-8"]} }
# ]

Customize

Add default header

Example1. Pass default header to FunnelHttp::Client#initialize

default_header = { "Authorization" => "Bearer xxxxxx" }

client = FunnelHttp::Client.new(default_header)

Example 2. Use FunnelHttp::Client#add_default_request_header

client.add_default_request_header("Authorization", "Bearer xxxxxx")

API Reference

https://sue445.github.io/funnel_http/

Performance

Depending on the case, funnel_http runs about 1.2x faster than pure-Ruby Thread :dash:

See benchmark/

Why?

funnel_http uses Go's goroutine for asynchronous processing of HTTP requests.

So this is faster than Ruby in many cases.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/funnel_http.

License

The gem is available as open source under the terms of the MIT License.