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
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.
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.