开发者

Need an HTTP gem for rails

I'm not pleased with Net::HTTP at all, and I'm lo开发者_如何学编程oking for a lightweight gem that will either replace that library or at the very least hide it from me.

Does anyone have any suggestions?


My vote goes to HTTParty. It's incredibly simple to use and can be as powerful as you choose. Here's a code sample:

HTTParty.get("http://maps.googleapis.com/maps/api/distancematrix/json?origins=New+York+NY&destinations=Los+Angeles+CA&mode=car&language=en&sensor=false")

Pretty simple stuff depending on what you're using it for.


Try the RestClient gem:

https://github.com/archiloque/rest-client


There are a few out there.

Ruby toolbox has a http client list: http://ruby-toolbox.com/categories/http_clients.html

Personally I usually use HTTParty... or sometimes Mechanize, it's good for submitting forms

I would recommend checking the docs of each, to see which one suits your purpose best.

Hope this helps.


You might want to check out the rest gem, it was created and tested so we could find the best performing http gems by wrapping those gems and creating a standard interface to them. Turns out HTTParty and RestClient are very slow gems so I wouldn't recommend those, although you can always swap out the underlying gem in rest to see for yourself without having to change your code (other than initialization). rest gem by default will be much, much faster.

It's also very easy to use:

@rest = Rest::Client.new()
@rest.get(url, options...)

More info: https://github.com/iron-io/rest

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜