Re:The Ruby Stdlib is not a Ghetto
by aaronbrethorst on Wednesday November 24, 2010 @08:45PM
(#1939082)
With all due respect, Net::HTTP is clunky. I'm typing the following from memory, too:
[ Parent
| on HN ]
that's great if all you're trying to do is HTTP GET. standard libs are supposed to make all use cases fairly easy. making an http post isn't too bad:
Net::HTTP.new(host, port).start do |http|
post = Net::HTTP::Post.new(url)
post.set_form_data('blah' => '123')
http.request(post)
end
Re:The Ruby Stdlib is not a Ghetto
by petercooper on Thursday November 25, 2010 @03:33AM
(#1939730)
That's "not too bad" if you're coming from Java. Thankfully most other Ruby libraries have significantly less verbose APIs than this.
There's a much simpler way to do POSTs with Net::HTTP:
response = Net::HTTP.post_form(URI.parse("http://example.com"), {:param => "val"})
Re:The Ruby Stdlib is not a Ghetto
by aaronbrethorst on Thursday November 25, 2010 @04:20AM
(#1939802)
Personally, I'm a big fan of open-uri for super-simple requests and HTTParty for anything more complex.
If you're doing more than one of those in a single document, having a persistent connection object and sending it request messages wins. (Though open-uri could actually do this, if it cached the connection objects by host:port.)