class Faraday::Request

rubocop:disable Style/StructInheritance
@return [RequestOptions] options
@!attribute options
@return [String] body
@!attribute body
@return [Faraday::Utils::Headers] headers
@!attribute headers
@return [Hash] query parameters
@!attribute params
@return [URI, String] the path
@!attribute path
@return [Symbol] the HTTP method of the Request
@!attribute http_method
end
req.body = ‘abc’<br>req = ‘2’ # also Header<br>req.params = ‘3’ # GET Param<br>req.headers = ‘2’ # Header
req.url ‘localhost’, ‘a’ => ‘1’ # ‘localhost?a=1
@connection.post do |req|
@example
Used to setup URLs, params, headers, and the request body in a sane manner.

def self.create(request_method)

Returns:
  • (Request) -

Other tags:
    Yieldparam: request -

Other tags:
    Yield: - for block customization, if block given

Parameters:
  • request_method (String) --
def self.create(request_method)
  new(request_method).tap do |request|
    yield(request) if block_given?
  end
end

def [](key)

Returns:
  • (Object) - value of the given header name

Parameters:
  • key (Object) -- key to look up in headers
def [](key)
  headers[key]
end

def []=(key, value)

Parameters:
  • value (Object) -- value of header
  • key (Object) -- key of header to write
def []=(key, value)
  headers[key] = value
end

def headers=(hash)

Parameters:
  • hash (Hash) -- new headers
def headers=(hash)
  if headers
    headers.replace hash
  else
    super
  end
end

def marshal_dump

Returns:
  • (Hash) - the hash ready to be serialized in Marshal.
def marshal_dump
  {
    http_method: http_method,
    body: body,
    headers: headers,
    path: path,
    params: params,
    options: options
  }
end

def marshal_load(serialised)

Parameters:
  • serialised (Hash) -- the serialised object.
def marshal_load(serialised)
  self.http_method = serialised[:http_method]
  self.body = serialised[:body]
  self.headers = serialised[:headers]
  self.path = serialised[:path]
  self.params = serialised[:params]
  self.options = serialised[:options]
end

def params=(hash)

Parameters:
  • hash (Hash) -- new params
def params=(hash)
  if params
    params.replace hash
  else
    super
  end
end

def to_env(connection)

Returns:
  • (Env) - the Env for this Request
def to_env(connection)
  Env.new(http_method, body, connection.build_exclusive_url(path, params),
          options, headers, connection.ssl, connection.parallel_manager)
end

def url(path, params = nil)

Returns:
  • (void) -

Parameters:
  • params (Hash, nil) --
  • path (URI, String) --
def url(path, params = nil)
  if path.respond_to? :query
    if (query = path.query)
      path = path.dup
      path.query = nil
    end
  else
    anchor_index = path.index('#')
    path = path.slice(0, anchor_index) unless anchor_index.nil?
    path, query = path.split('?', 2)
  end
  self.path = path
  self.params.merge_query query, options.params_encoder
  self.params.update(params) if params
end