Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use Faraday over Net::HTTP?

Why would someone use the Faraday gem vs directly using Net::HTTP? What is the benefit of using a wrapper like this?

like image 963
user3084728 Avatar asked Jan 02 '14 18:01

user3084728


1 Answers

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.

like image 188
Chris Cashwell Avatar answered Nov 06 '22 17:11

Chris Cashwell