Skip to content
instance method

Net::HTTP#request_get

(::String path, ?::Net::headers initheader) ?{ (::Net::HTTPResponse response) -> void } -> ::Net::HTTPResponse
request_get(path, initheader = nil) { |response| ... }

Sends a GET request to the server; forms the response into a Net::HTTPResponse object.

The request is based on the Net::HTTP::Get object created from string path and initial headers hash initheader.

With no block given, returns the response object:

Example
http = Net::HTTP.new(hostname)
http.request_get('/todos') # => #<Net::HTTPOK 200 OK readbody=true>

With a block given, calls the block with the response object and returns the response object:

Example
http.request_get('/todos') do |res|
  p res
end # => #<Net::HTTPOK 200 OK readbody=true>

Output:

Example
#<Net::HTTPOK 200 OK readbody=false>