Why would someone use the Faraday gem vs directly using Net::HTTP? What is the benefit of using a wrapper like this?
Asked
Active
Viewed 3,874 times
14
-
This is going to draw opinions, not facts. – the Tin Man Jan 02 '14 at 19:56
-
1There are objective reasons to use Faraday over Net::HTTP. – davogones Jan 03 '14 at 02:13
1 Answers
14
Using the Net::HTTP
adapter directly is fine, it's just binding your code to a particular interface which may differ from alternate tools. The main reason one would use Faraday
is that it wraps multiple adapters, one of which is Net::HTTP
. If you're using Faraday
and start out with Net:HTTP
, you can later decide to use Excon
, Typhoeus
, Patron
or EventMachine
without changing more than a line or two of configuration. Had you used Net::HTTP
directly, you'd have to change a lot of implementation-specific code to switch to another adapter.

Chris Cashwell
- 22,308
- 13
- 63
- 94
-
2Good explanation. You should also mention middleware. For example, I use JSON middleware to automatically encode my request as JSON and decode the response from JSON. – davogones Jan 03 '14 at 02:14
-
2Faraday should also help normalize exceptions across all of the libraries as well, correct? – user3084728 Jan 06 '14 at 20:17
-
3Yes @user3084728, Faraday will catch each adapter's exceptions and re-throw them as Faraday exceptions. – Chris Cashwell Jan 06 '14 at 21:12