# Net::HTTP

**URL:** <https://discuss.rubyonrails.org/t/net-http/66960>\
**Category:** rubyonrails-talk\
**Created:** [May 7, 2013, 5:43pm UTC](https://discuss.rubyonrails.org/t/net-http/66960 "2013-05-07T17:43:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Merlino](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@John\_Merlino](https://discuss.rubyonrails.org/u/John_Merlino)\
**Post date:** [May 7, 2013, 5:43pm UTC](https://discuss.rubyonrails.org/t/net-http/66960/1 "2013-05-07T17:43:32Z")

</div>

I'm looking at the documentation:

> **[Class: Net::HTTP (Ruby 2.0.0)](https://ruby-doc.org/stdlib-2.0.0/libdoc/net/http/rdoc/Net/HTTP.html)**
>
> Class : Net::HTTP - Ruby 2.0.0

And I notice two uses of Net::HTTP. Both are using GET requests. But what's the difference? When to use which?

Net::HTTP.start(uri.host, uri.port) do |http| &nbsp;&nbsp;request = Net::HTTP::Get.new uri

&nbsp;&nbsp;response = http.request request # Net::HTTPResponse object end

uri = URI('[Example Domain](http://example.com/index.html)’) res = Net::HTTP.get\_response(uri)

---

<div class="post-metadata">

**Author:** ![Tamara\_Temple](https://avatars.discourse-cdn.com/v4/letter/t/c37758/32.png) [@Tamara\_Temple](https://discuss.rubyonrails.org/u/Tamara_Temple)\
**Post date:** [May 8, 2013, 2:00am UTC](https://discuss.rubyonrails.org/t/net-http/66960/2 "2013-05-08T02:00:44Z")

</div>

I'm not sure there is a definitive answer, but my heuristic is that if I'm going to do a few things with the connection, I'll use the first form (send code into the block, as this ensures the connection shuts down at the end of the block.

If I'm only getting one thing and then carrying on with it with no need for using that connection again, I'll use the second form.

But again, this is only a heuristic, and not definitive.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [May 8, 2013, 9:56am UTC](https://discuss.rubyonrails.org/t/net-http/66960/3 "2013-05-08T09:56:02Z")

</div>

> I’m looking at the documentation:
> 
> [http://ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html](http://ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html)
> 
> And I notice two uses of Net::HTTP. Both are using GET requests. But
> 
> what’s the difference? When to use which?

It’s the usual tradeoff between convenience and extensiveness. The long form allows you to pipeline requests, set more options on the request (eg headers etc.) but a lot of the time you just want to grab the content from a url and don’t need all the ceremony

Fred
