Faraday Typhoeus Adapter
Add this line to your application's Gemfile:
And then execute:
$ bundle install
Or install it yourself as:
$ gem install faraday-typhoeus
conn = Faraday.new(...) do |f| f.adapter :typhoeus end
Note that block-style configuration for the adapter is not currently supported.
conn = Faraday.new(...) do |f| f.adapter :typhoeus, forbid_reuse: true, maxredirs: 1 end
The adapter supports Typhoeus's parallel request functionality:
conn = Faraday.new(...) do |f| f.request :url_encoded f.response :logger f.adapter :typhoeus end responses =  conn.in_parallel do # responses.body will be null here since the requests have not been # completed responses = [ conn.get('/first'), conn.get('/second'), ] end # after it has been completed the response information is fully available in # response.status, etc responses.body responses.body
The adapter supports streamed responses via the
conn = Faraday.new(...) do |f| f.adapter :typhoeus end # Streaming chunks =  conn.get('/stream') do |req| req.options.on_data proc do |chunk, received_bytes| chunks << chunk end end body = chunks.join # Server-Sent Event Polling body = nil begin conn.get('/events') do |req| req.options.timeout = 30 req.options.on_data = proc do |chunk| # stop listening once we get some data (YMMV) if chunk.start_with?('data: ') body = chunk :abort # abort the request, we're done end end end rescue Faraday::ConnectionFailed => ex raise ex unless body end
- See Typhoeus Documentation for more info.
After checking out the repo, run
bin/setup to install dependencies. Then, run
bin/test to run the tests. You can also run
bin/console for an interactive prompt that will allow you to experiment.
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 tags, and push the
.gem file to rubygems.org.
- [ ] Better tests for parallel functionality (can port them over from Typhoeus)
- [ ] Support block-based configuration like other adapters
- [ ] Refactor the adapter a bit to look more like other Faraday 2 adapters (use
- [x] Compression support
- [x] Reason-phrase parsing support
Bug reports and pull requests are welcome on GitHub.
The gem is available as open source under the terms of the license.