module Faraday

This is the main namespace for Faraday.

It provides methods to create {Connection} objects, and HTTP-related methods to use directly.

@example Helpful class methods for easy usage

Faraday.get "http://faraday.com"

@example Helpful class method ‘.new` to create {Connection} objects.

conn = Faraday.new "http://faraday.com"
conn.get '/'

Faraday namespace.

Constants

CONTENT_TYPE
ConnectionOptions

@!parse

# ConnectionOptions contains the configurable properties for a Faraday
# connection object.
class ConnectionOptions < Options; end
Env

@!parse

# @!attribute method
#   @return [Symbol] HTTP method (`:get`, `:post`)
#
# @!attribute body
#   @return [String] The request body that will eventually be converted to a
#   string.
#
# @!attribute url
#   @return [URI] URI instance for the current request.
#
# @!attribute request
#   @return [Hash] options for configuring the request.
#   Options for configuring the request.
#
#   - `:timeout`       - time limit for the entire request (Integer in
#                        seconds)
#   - `:open_timeout`  - time limit for just the connection phase (e.g.
#                        handshake) (Integer in seconds)
#   - `:read_timeout`  - time limit for the first response byte received from
#                        the server (Integer in seconds)
#   - `:write_timeout` - time limit for the client to send the request to the
#                        server (Integer in seconds)
#   - `:on_data`       - Proc for streaming
#   - `:proxy`         - Hash of proxy options
#       - `:uri`         - Proxy server URI
#       - `:user`        - Proxy server username
#       - `:password`    - Proxy server password
#
# @!attribute request_headers
#   @return [Hash] HTTP Headers to be sent to the server.
#
# @!attribute ssl
#   @return [Hash] options for configuring SSL requests
#
# @!attribute parallel_manager
#   @return [Object] sent if the connection is in parallel mode
#
# @!attribute params
#   @return [Hash]
#
# @!attribute response
#   @return [Response]
#
# @!attribute response_headers
#   @return [Hash] HTTP headers from the server
#
# @!attribute status
#   @return [Integer] HTTP response status code
#
# @!attribute reason_phrase
#   @return [String]
class Env < Options; end
METHODS_WITH_BODY
METHODS_WITH_QUERY
ProxyOptions

@!parse

# ProxyOptions contains the configurable properties for the proxy
# configuration used when making an HTTP request.
class ProxyOptions < Options; end
Request

Used to setup URLs, params, headers, and the request body in a sane manner.

@example

@connection.post do |req|
  req.url 'http://localhost', 'a' => '1' # 'http://localhost?a=1'
  req.headers['b'] = '2' # Header
  req.params['c']  = '3' # GET Param
  req['b']         = '2' # also Header
  req.body = 'abc'
end

@!attribute http_method

@return [Symbol] the HTTP method of the Request

@!attribute path

@return [URI, String] the path

@!attribute params

@return [Hash] query parameters

@!attribute headers

@return [Faraday::Utils::Headers] headers

@!attribute body

@return [String] body

@!attribute options

@return [RequestOptions] options
RequestOptions

@!parse

# RequestOptions contains the configurable properties for a Faraday request.
class RequestOptions < Options; end
SSLOptions

@!parse

# SSL-related options.
#
# @!attribute verify
#   @return [Boolean] whether to verify SSL certificates or not
#
# @!attribute verify_hostname
#   @return [Boolean] whether to enable hostname verification on server certificates
#           during the handshake or not (see https://github.com/ruby/openssl/pull/60)
#
# @!attribute ca_file
#   @return [String] CA file
#
# @!attribute ca_path
#   @return [String] CA path
#
# @!attribute verify_mode
#   @return [Integer] Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
#
# @!attribute cert_store
#   @return [OpenSSL::X509::Store] certificate store
#
# @!attribute client_cert
#   @return [String, OpenSSL::X509::Certificate] client certificate
#
# @!attribute client_key
#   @return [String, OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] client key
#
# @!attribute certificate
#   @return [OpenSSL::X509::Certificate] certificate (Excon only)
#
# @!attribute private_key
#   @return [OpenSSL::PKey::RSA, OpenSSL::PKey::DSA] private key (Excon only)
#
# @!attribute verify_depth
#   @return [Integer] maximum depth for the certificate chain verification
#
# @!attribute version
#   @return [String, Symbol] SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-ssl_version-3D)
#
# @!attribute min_version
#   @return [String, Symbol] minimum SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-min_version-3D)
#
# @!attribute max_version
#   @return [String, Symbol] maximum SSL version (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-max_version-3D)
#
# @!attribute ciphers
#   @return [String] cipher list in OpenSSL format (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL/SSLContext.html#method-i-ciphers-3D)
class SSLOptions < Options; end
VERSION

Attributes

@overload default_adapter

Gets the Symbol key identifying a default Adapter to use
for the default {Faraday::Connection}. Defaults to `:net_http`.
@return [Symbol] the default adapter

@overload default_adapter=(adapter)

Updates default adapter while resetting {.default_connection}.
@return [Symbol] the new default_adapter.

Option for the default_adapter

@return [Hash] default_adapter options

Tells Faraday to ignore the environment proxy (http_proxy). Defaults to ‘false`. @return [Boolean]

Gets or sets the path that the Faraday libs are loaded from. @return [String]

The root path that Faraday is being loaded from.

This is the root from where the libraries are auto-loaded.

@return [String]

Public Class Methods

Documented elsewhere, see default_adapter reader

# File lib/faraday.rb, line 102
def default_adapter=(adapter)
  @default_connection = nil
  @default_adapter = adapter
end

@overload default_connection

Gets the default connection used for simple scripts.
@return [Faraday::Connection] a connection configured with
the default_adapter.

@overload default_connection=(connection)

@param connection [Faraday::Connection]
Sets the default {Faraday::Connection} for simple scripts that
access the Faraday constant directly, such as
<code>Faraday.get "https://faraday.com"</code>.
# File lib/faraday.rb, line 120
def default_connection
  @default_connection ||= Connection.new(default_connection_options)
end

Gets the default connection options used when calling {Faraday#new}.

@return [Faraday::ConnectionOptions]

# File lib/faraday.rb, line 127
def default_connection_options
  @default_connection_options ||= ConnectionOptions.new
end

Sets the default options used when calling {Faraday#new}.

@param options [Hash, Faraday::ConnectionOptions]

# File lib/faraday.rb, line 134
def default_connection_options=(options)
  @default_connection = nil
  @default_connection_options = ConnectionOptions.from(options)
end

Initializes a new {Connection}.

@param url [String,Hash] The optional String base URL to use as a prefix

for all requests.  Can also be the options Hash. Any of these
values will be set on every request made, unless overridden
for a specific request.

@param options [Hash] @option options [String] :url Base URL @option options [Hash] :params Hash of unencoded URI query params. @option options [Hash] :headers Hash of unencoded HTTP headers. @option options [Hash] :request Hash of request options. @option options [Hash] :ssl Hash of SSL options. @option options [Hash] :proxy Hash of Proxy options. @return [Faraday::Connection]

@example With an URL argument

Faraday.new 'http://faraday.com'
# => Faraday::Connection to http://faraday.com

@example With an URL argument and an options hash

Faraday.new 'http://faraday.com', params: { page: 1 }
# => Faraday::Connection to http://faraday.com?page=1

@example With everything in an options hash

Faraday.new url: 'http://faraday.com',
            params: { page: 1 }
# => Faraday::Connection to http://faraday.com?page=1
# File lib/faraday.rb, line 96
def new(url = nil, options = {}, &block)
  options = Utils.deep_merge(default_connection_options, options)
  Faraday::Connection.new(url, options, &block)
end
Calls superclass method
# File lib/faraday.rb, line 107
def respond_to_missing?(symbol, include_private = false)
  default_connection.respond_to?(symbol, include_private) || super
end