Back to Faraday

Connection Options

docs/customization/connection-options.md

2.14.12.6 KB
Original Source

Connection Options

When initializing a new Faraday connection with Faraday.new, you can pass a hash of options to customize the connection. All these options are optional.

OptionTypeDefaultDescription
:requestHashnilHash of request options. Will be use to build RequestOptions.
:proxyURI, String, HashnilProxy options, either as a URL or as a Hash of ProxyOptions.
:sslHashnilHash of SSL options. Will be use to build SSLOptions.
:urlURI, StringnilURI or String base URL. This can also be passed as positional argument.
:parallel_managernilDefault parallel manager to use. This is normally set by the adapter, but you have the option to override it.
:paramsHashnilURI query unencoded key/value pairs.
:headersHashnilHash of unencoded HTTP header key/value pairs.
:builder_classClassRackBuilderA custom class to use as the middleware stack builder.
:builderObjectRackbuilder.newAn instance of a custom class to use as the middleware stack builder.

Example

ruby
options = {
  request: {
    open_timeout: 5,
    timeout: 5
  },
  proxy: {
    uri: 'https://proxy.com',
    user: 'proxy_user',
    password: 'proxy_password'
  },
  ssl: {
    ca_file: '/path/to/ca_file',
    ca_path: '/path/to/ca_path',
    verify: true
  },
  url: 'https://example.com',
  params: { foo: 'bar' },
  headers: { 'X-Api-Key' => 'secret', 'X-Api-Version' => '2' }
}

conn = Faraday.new(options) do |faraday|
  # ...
end