Is it safe to reuse Faraday connection objects, or is it better to recreate them every time?
def connection
@connection ||= Faraday.new('http://example.com') do |conn|
conn.request :url_encoded
# more configuration
end
end
I think it's safe to reuse them (I have, a lot). I don't see it really covered one way or another in the documentation but the presence of "Per-request options" (as opposed to per-connection) at least implies that you can rely on making multiple requests with the same connection.
https://github.com/lostisland/faraday/blob/52e30bf8e8d79159f332088189cb7f7e536d1ba1/lib/faraday/connection.rb#L502
connection.get
.post
and all other methods duplicates params etc here.
It means each request shares nothing with each other and the parent Connection object.
It's safe to reuse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With