Last active
March 25, 2018 15:55
-
-
Save jonniesweb/5fc677b08a071c05e7c64b12af663151 to your computer and use it in GitHub Desktop.
A simple example of using the Typhoeus parallel HTTP client library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setup requests | |
request_one = Typhoeus.get("www.example.com") | |
request_two = Typhoeus.get("www.google.com") | |
request_three = Typhoeus.get("www.bing.com") | |
# initialize a "Hydra" for performing requests in parallel | |
hydra = Typhoeus::Hydra.new | |
hydra.queue(request_one) | |
hydra.queue(request_two) | |
hydra.queue(request_three) | |
# run and wait for all requests to finish | |
hydra.run | |
# fetch the body of the response | |
puts request_one.response.body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment