Skip to content
instance method

Net::HTTP#start

[T] () { (::Net::HTTP) -> T } -> T
() -> ::Net::HTTP
start() { |http| ... }

Starts an HTTP session.

Without a block, returns self:

Example
http = Net::HTTP.new(hostname)
# => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
http.start
# => #<Net::HTTP jsonplaceholder.typicode.com:80 open=true>
http.started? # => true
http.finish

With a block, calls the block with self, finishes the session when the block exits, and returns the block’s value:

Example
http.start do |http|
  http
end
# => #<Net::HTTP jsonplaceholder.typicode.com:80 open=false>
http.started? # => false
See also .start #set_debug_output #started? #send_request also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0