Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default request timeout value? #417

Closed
subvertallchris opened this issue Sep 23, 2014 · 5 comments
Closed

Default request timeout value? #417

subvertallchris opened this issue Sep 23, 2014 · 5 comments

Comments

@subvertallchris
Copy link

Rather than setting a timeout per request, is it possible to set a default across all connections opened within a session?

@mislav
Copy link
Contributor

mislav commented Sep 23, 2014

Any option that can be edited per request can also be set on the Connection instance that you can use to make all your requests.

conn = Faraday.new("https://api.example.com", request: {
  open_timeout: 2,   # opening a connection
  timeout: 5         # waiting for response
})

conn.get(...)

@mislav mislav closed this as completed Sep 23, 2014
@subvertallchris
Copy link
Author

Perfect, thanks!

@kylev
Copy link

kylev commented Jun 2, 2016

Since I see very few correct mentions of this elsewhere, the builder version of this in 0.9.2 is this, with the options attribute being the request option defaults:

Faraday::Connection.new('https://api.example.com') do |builder|
  builder.options[:open_timeout] = 2
  builder.options[:timeout] = 5
  builder.adapter Faraday.default_adapter
end

@neohunter
Copy link

Both examples explain how to set per request, How I can set globally?

@iMacTia
Copy link
Member

iMacTia commented Jan 14, 2021

@neohunter the example above will set it for each request done from that connection. Faraday doesn't currently support a global setting for all connections, but that shouldn't really be necessary as the number of connections you manage should be just a few (actually, only one in most cases).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants