Ruby: send HTTP GET request, receive JSON output - what is the fastest way?
My application will call Facebook API multipl开发者_JAVA百科e times: the example.
What is the fastest / most reliable way to send HTTP GET requests and parse the returned output in JSON format?
Should I use Curl::Easy? If yes, how does it deal with JSON?
Use httparty
it includes crack for json. Use it like so:-
httparty "http://twitter.com/statuses/public_timeline.json"
What does "multiple times" mean? Twice? X times every n minutes? Thousands of times an hour?
Ruby has Typhoeus/Hydra, which handles huge numbers of concurrent requests. Processing the JSON is easy compared to handling multiple requests.
The Times example is a good starting point. Stick your JSON processing in the on_complete
handler.
Check out crack. Dead simple and just works.
精彩评论