问题描述
Faraday 是首选的 ruby HTTP 客户端库.为什么比 HTTParty 更可取?
Faraday is the ruby HTTP client library of choice. Why is it preferable to use it over HTTParty?
我想比较的一些事情是:
Some things that I would like compared are:
- 性能
- 架构
- 易于使用
- Faraday 中存在但 HTTParty 中没有的功能(反之亦然)
- 使法拉第成为首选图书馆的任何其他方面.
推荐答案
它们在很多方面都不同,但恕我直言,这就是本质:
They differ in many aspects, but here's the essence IMHO:
HTTParty:- 使用网络/http- 一些魔法(例如解析 JSON 响应)
HTTParty:- Uses net/http- Some magic (e.g. parse JSON responses)
法拉第:- 大多数 http 库的包装器(excon、typhoeus、net-http-persistent 等)- 允许制作适合您特定需求的请求和响应中间件.
Faraday:- A wrapper around most of the http libraries out there (excon, typhoeus, net-http-persistent, etc.)- Allows to craft the request and response middleware that suits your specific needs.
我个人更喜欢 Faraday,因为它允许我切换到任何 http 库,并且因为它允许对请求和响应进行非常精细的控制.
I personally prefer Faraday, as it allows me to switch to any http library, and because it allows very fine-grain control over the request and response.
这篇关于法拉第 vs HTTParty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!