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_query

request_query(path, data, initheader = nil) { |response| ... }

Sends a QUERY request to the server; returns an instance of a subclass of Net::HTTPResponse.

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

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

With no block given, returns the response object:

Example
http = Net::HTTP.new(hostname)
http.request_query('/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_query('/todos') do |res|
  p res
end # => #<Net::HTTPOK 200 OK readbody=true>

Output:

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