Module: Faraday

Defined in:
lib/faraday/error.rb,
lib/faraday/utils.rb,
lib/faraday/adapter.rb,
lib/faraday/methods.rb,
lib/faraday/options.rb,
lib/faraday/request.rb,
lib/faraday/version.rb,
lib/faraday/autoload.rb,
lib/faraday/response.rb,
lib/faraday/file_part.rb,
lib/faraday/connection.rb,
lib/faraday/middleware.rb,
lib/faraday/param_part.rb,
lib/faraday/options/env.rb,
lib/faraday/adapter/rack.rb,
lib/faraday/rack_builder.rb,
lib/faraday/adapter/excon.rb,
lib/faraday/request/retry.rb,
lib/faraday/utils/headers.rb,
lib/faraday/adapter/patron.rb,
lib/faraday/adapter/em_http.rb,
lib/faraday/response/logger.rb,
lib/faraday/adapter/typhoeus.rb,
lib/faraday/adapter_registry.rb,
lib/faraday/dependency_loader.rb,
lib/faraday/logging/formatter.rb,
lib/faraday/request/multipart.rb,
lib/faraday/utils/params_hash.rb,
lib/faraday/adapter/httpclient.rb,
lib/faraday/middleware_registry.rb,
lib/faraday/options/ssl_options.rb,
lib/faraday/request/url_encoded.rb,
lib/faraday/adapter/em_synchrony.rb,
lib/faraday/response/raise_error.rb,
lib/faraday/options/proxy_options.rb,
lib/faraday/request/authorization.rb,
lib/faraday/options/request_options.rb,
lib/faraday/request/instrumentation.rb,
lib/faraday/options/connection_options.rb,
lib/faraday/adapter/net_http_persistent.rb,
lib/faraday/encoders/flat_params_encoder.rb,
lib/faraday/request/basic_authentication.rb,
lib/faraday/request/token_authentication.rb,
lib/faraday/encoders/nested_params_encoder.rb,
lib/faraday/adapter/em_synchrony/parallel_manager.rb,
lib/faraday.rb

Overview

This is the main namespace for Faraday.

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

Examples:

Helpful class methods for easy usage

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

Helpful class method .new to create Connection objects.

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

Defined Under Namespace

Modules: AutoloadHelper, DecodeMethods, DependencyLoader, EncodeMethods, FlatParamsEncoder, Logging, MiddlewareRegistry, NestedParamsEncoder, Utils Classes: Adapter, AdapterRegistry, BadRequestError, ClientError, CompositeReadIO, ConflictError, Connection, ConnectionFailed, ConnectionOptions, Env, Error, ForbiddenError, Middleware, NilStatusError, Options, ParamPart, ParsingError, ProxyAuthError, ProxyOptions, RackBuilder, Request, RequestOptions, ResourceNotFound, Response, RetriableResponse, SSLError, SSLOptions, ServerError, TimeoutError, UnauthorizedError, UnprocessableEntityError

Constant Summary collapse

METHODS_WITH_QUERY =
%w[get head delete trace].freeze
METHODS_WITH_BODY =
%w[post put patch].freeze
VERSION =
'1.3.0'
FilePart =

The uploaded binary data's content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:

::UploadIO
UploadIO =
Deprecated.

Use FilePart instead of this class. It behaves identically, with a matching name to ParamPart.

Multipart value used to POST a file.

::UploadIO
Parts =
::Parts
Timer =
Timeout

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.default_adapterSymbol .default_adapter=(adapter) ⇒ Symbol

Overloads:

  • .default_adapterSymbol

    Gets the Symbol key identifying a default Adapter to use for the default Connection. Defaults to :net_http.

    Returns:

    • (Symbol)

      the default adapter

  • .default_adapter=(adapter) ⇒ Symbol

    Updates default adapter while resetting default_connection.

    Returns:

    • (Symbol)

      the new default_adapter.


64
65
66
# File 'lib/faraday.rb', line 64

def default_adapter
  @default_adapter
end

.default_connectionFaraday::Connection .default_connection=(connection) ⇒ Object

Overloads:


138
139
140
# File 'lib/faraday.rb', line 138

def default_connection
  @default_connection ||= Connection.new(default_connection_options)
end

.ignore_env_proxyBoolean

Tells Faraday to ignore the environment proxy (http_proxy). Defaults to false.

Returns:

  • (Boolean)

72
73
74
# File 'lib/faraday.rb', line 72

def ignore_env_proxy
  @ignore_env_proxy
end

.lib_pathString

Gets or sets the path that the Faraday libs are loaded from.

Returns:

  • (String)

55
56
57
# File 'lib/faraday.rb', line 55

def lib_path
  @lib_path
end

.root_pathString

The root path that Faraday is being loaded from.

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

Returns:

  • (String)

51
52
53
# File 'lib/faraday.rb', line 51

def root_path
  @root_path
end

Instance Attribute Details

#content_typeFaraday::FilePart, ... (readonly)

The uploaded binary data's content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:


53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO

#ioFaraday::FilePart, ... (readonly)

The uploaded binary data's content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:


53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO

#optsFaraday::FilePart, ... (readonly)

The uploaded binary data's content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:


53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO

#original_filenameFaraday::FilePart, ... (readonly)

The uploaded binary data's content type.

The base filename, taken either from the filename_or_io or filename arguments in #initialize.

Extra String key/value pairs to make up the header for this uploaded file.

The open IO object for the uploaded file.

Returns:


53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO

Class Method Details

.default_connection_optionsFaraday::ConnectionOptions

Gets the default connection options used when calling new.


145
146
147
# File 'lib/faraday.rb', line 145

def default_connection_options
  @default_connection_options ||= ConnectionOptions.new
end

.default_connection_options=(options) ⇒ Object

Sets the default options used when calling new.

Parameters:


152
153
154
155
# File 'lib/faraday.rb', line 152

def default_connection_options=(options)
  @default_connection = nil
  @default_connection_options = ConnectionOptions.from(options)
end

.new(url = nil, options = {}, &block) ⇒ Faraday::Connection

Initializes a new Connection.

Examples:

With an URL argument

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

With an URL argument and an options hash

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

With everything in an options hash

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

Parameters:

  • url (String, Hash) (defaults to: nil)

    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.

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

Options Hash (options):

  • :url (String)

    Base URL

  • :params (Hash)

    Hash of unencoded URI query params.

  • :headers (Hash)

    Hash of unencoded HTTP headers.

  • :request (Hash)

    Hash of request options.

  • :ssl (Hash)

    Hash of SSL options.

  • :proxy (Hash)

    Hash of Proxy options.

Returns:


101
102
103
104
# File 'lib/faraday.rb', line 101

def new(url = nil, options = {}, &block)
  options = default_connection_options.merge(options)
  Faraday::Connection.new(url, options, &block)
end

.respond_to_missing?(symbol, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

125
126
127
# File 'lib/faraday.rb', line 125

def respond_to_missing?(symbol, include_private = false)
  default_connection.respond_to?(symbol, include_private) || super
end

Instance Method Details

#initialize(filename_or_io, content_type, filename = nil, opts = {}) ⇒ Object

Parameters:

  • filename_or_io (String, IO)

    Either a String filename to a local file or an open IO object.

  • content_type (String)

    String content type of the file data.

  • filename (String) (defaults to: nil)

    Optional String filename, usually to add context to a given IO object.

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

    Optional Hash of String key/value pairs to describethis this uploaded file. Expected Header keys include:

    • Content-Transfer-Encoding - Defaults to "binary"
    • Content-Disposition - Defaults to "form-data"
    • Content-Type - Defaults to the content_type argument.
    • Content-ID - Optional.

53
# File 'lib/faraday/file_part.rb', line 53

FilePart = ::UploadIO