Back to Faraday

Request Options

docs/customization/request-options.md

2.14.12.7 KB
Original Source

Request Options

Request options can be provided to the connection constructor or set on a per-request basis. All these options are optional.

OptionTypeDefaultDescription
:params_encoderClassFaraday::Utils.nested_params_encoder (NestedParamsEncoder)A custom class to use as the params encoder.
:proxyURI, String, HashnilProxy options, either as a URL or as a Hash of ProxyOptions.
:bindHashnilHash of bind options. Requires the :host and :port keys.
:timeoutInteger, Floatnil (adapter default)The max number of seconds to wait for the request to complete.
:open_timeoutInteger, Floatnil (adapter default)The max number of seconds to wait for the connection to be established.
:read_timeoutInteger, Floatnil (adapter default)The max number of seconds to wait for one block to be read.
:write_timeoutInteger, Floatnil (adapter default)The max number of seconds to wait for one block to be written.
:boundaryStringnilThe boundary string for multipart requests.
:contextHashnilArbitrary data that you can pass to your request.
:on_dataProcnilA callback that will be called when data is received. See Streaming

Example

ruby
# Request options can be passed to the connection constructor and will be applied to all requests.
request_options = {
  params_encoder: Faraday::FlatParamsEncoder,
  timeout: 5
}

conn = Faraday.new(request: request_options) do |faraday|
  # ...
end

# You can then override them on a per-request basis.
conn.get('/foo') do |req|
  req.options.timeout = 10
end