Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Net::HTTPSession#request_get

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>