20

Faraday是首选的 ruby​​ HTTP 客户端库。为什么最好使用它而不是HTTParty

我想比较的一些事情是:

  • 表现
  • 建筑学
  • 使用方便
  • 法拉第中存在但 HTTParty 中不存在的功能(反之亦然)
  • 任何其他使法拉第图书馆成为首选的东西。
4

2 回答 2

23

它们在许多方面都不同,但恕我直言,这是本质:

HTTParty: - 使用 net/http - 一些魔法(例如解析 JSON 响应)

Faraday: - 一个围绕大多数 http 库(excon、typhoeus、net-http-persistent 等)的包装器 - 允许制作适合您特定需求的请求和响应中间件。

我个人更喜欢 Faraday,因为它允许我切换到任何 http 库,并且因为它允许对请求和响应进行非常细粒度的控制。

于 2012-10-11T17:14:53.410 回答
7

I was at the point of having to make the same decision yesterday. However, I just need a library that can do simple http requests, nothing fancy... I was however looking for something that is easier to use than Net::HTTP.

For my purposes, both libraries seemed equally well suited, so I decided to go with the one introducing less overhead. Since I also use the twitter gem in this project, I went with faraday since the twitter gem already depends on it and I get it included in my project for "free"...

于 2012-10-12T07:45:34.750 回答