Method: Typhoeus::Request#initialize

Defined in:
lib/typhoeus/request.rb

#initialize(url, options = {}) ⇒ Typhoeus::Request

Note:

See Ethon::Easy#initialize for more options.

Create a new request.

Examples:

Simplest request.

response = Typhoeus::Request.new("www.example.com").run

Request with url parameters.

response = Typhoeus::Request.new(
  "www.example.com",
  params: {a: 1}
).run

Request with a body.

response = Typhoeus::Request.new(
  "www.example.com",
  body: {b: 2}
).run

Request with parameters and body.

response = Typhoeus::Request.new(
  "www.example.com",
  params: {a: 1},
  body: {b: 2}
).run

Create a request and allow follow redirections.

response = Typhoeus::Request.new(
  "www.example.com",
  followlocation: true
).run

Parameters:

  • url (String)

    The url to request.

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

    The options.

Options Hash (options):

  • :params (Hash)

    Translated into url parameters.

  • :body (Hash)

    Translated into HTTP POST request body.

See Also:

Since:

  • 0.5.0



107
108
109
110
111
112
113
# File 'lib/typhoeus/request.rb', line 107

def initialize(url, options = {})
  @url = url
  @original_options = options
  @options = options.dup

  set_defaults
end