November 2013
I know convention over configuration is common in Ruby programming, but it strikes me that the API of the Faraday object being constructed does not *always* require an adapter as a strong dependency. Forgive my Java:
new Faraday(new FaradayDefaultAdapter()).addMiddleware(...)
I think this "defaulting" is leading you to some strong coupling to the Adapter, which we know can be a problem if you want to unit test your requests. The documentation shows you'll need to pass in a test Adapter:
test = Faraday.new do |builder|
builder.adapter :test
end
(there is also the now-classic problem of accidentally charging a real credit card during test runs: http://misko.hevery.com/200... describes it better than me)
1 reply
November 2013
▶ giorgio_sironi
Going back to Java, I'd have this in mind:
Faraday.withDefaultAdapter().addMiddleware(...)
or, perhaps even better, adding any other sensible defaults:
Faraday.withSensibleDefaultStack().addMiddleware(...)
I'd rather couple myself to Faraday by *intent* ("I want the default stack"), than by implementation details (knowing what the "default stack" includes and how to instantiate the pieces and in which order to apply them). If, later, I need those details, then I simply inline `withSensibleDefaultStack()` and I can see how it's done.
I love Misko's article. Warning people about singletons started my career. http://www.ibm.com/develope... I don't want a singleton: I want Faraday to hide some implementation details from me without making it impossible for me to gain access to them when, later, I need them. I think my proposal achieves that.
June 2016
Eh, Faraday... this almost makes me want to share how I lost time to that library. Suffice to say it's not very good.
Try http://docs.python-requests... - or is that the wrong language?
July 2019
Worked like a charm, thanks