Method: Manticore::Client#get

Defined in:
lib/manticore/client.rb

#get(url, options = {}, &block) ⇒ Response

Perform a HTTP GET request

Examples:

Simple usage

body = client.get("http://example.com/some/resource", params: {foo: "bar"}, headers: {"X-Custom-Header" => "whee"}).body

Passing a block as the success handler:

body = client.get("http://example.com/some/resource", params: {foo: "bar"}, headers: {"X-Custom-Header" => "whee"}) {|response| response.body }

Explicit success handler:

body = client.get("http://example.com/some/resource", params: {foo: "bar"}, headers: {"X-Custom-Header" => "whee"}).
  on_success {|response| response.body }

Parameters:

  • url (String)

    URL to request

  • options (Hash) (defaults to: {})

Options Hash (options):

  • query (Hash)

    Hash of options to be added to the URL as part of the query string

  • params (Hash)

    Hash of options to pass as a request body. For GET, HEAD, and DELETE requests, :params will be treated as :query if :query is not present.

  • headers (Hash)

    Hash of options to pass as additional request headers

  • proxy (String)

    Proxy host in form: proxy.org:1234

  • proxy (Hash)

    Proxy host in form: ‘proxy.org’[, port: 80[, scheme: ‘http’]]

  • proxy (URI)

    Proxy host as a URI object

  • connect_timeout (Float)

    Request-specific connect timeout (in seconds)

  • socket_timeout (Float)

    Request-specific socket timeout (in seconds)

  • request_timeout (Float)

    Request-specific request timeout (in seconds)

  • max_redirects (Integer)

    Request-specific maximum redirect limit

  • follow_redirects (Boolean)

    Specify whether this request should follow redirects

  • auth (Hash)

    Specify authentication for the request

  • auth[:user] (String)

    Username to auth with

  • auth[:password] (String)

    Password to auth with

  • auth[:eager] (Boolean)

    Eagerly offer the Authorization header before the server challenges for it. You should not use this unless you know you specifically need it, as misuse of it can leak user credentials.

Returns:

Raises:



262
263
264
265
266
# File 'lib/manticore/client.rb', line 262

def get(url, options = {}, &block)
  options = treat_params_as_query(options)
  get_class = options[:body] ? HttpGetWithEntity : HttpGet
  request get_class, url, options, &block
end