![]() I would like to hear your opinions and suggestions for improvements. One of the things I did is read another code base that I though was well written (calabash-ios). But there's been a new requirement and I tried my best writing it better, more cleanly compared to my previous code. If it had existed 10 years ago, we wouldn't have all these different clients in the first place I don't think.For quite a while now I've been writing a bit of Ruby code, but so far I still don't think it was good idiomatic Ruby. Personally, I think in 2021 you should just go with http-rb as a default. See the Installation page for details on using. On Windows machines, you can use RubyInstaller. On macOS machines, you can use third-party tools ( rbenv and RVM ). And personally I find it's API very weird for when you actually want an HTTP client. We have several tools on each major platform to install Ruby: On Linux/UNIX, you can use the package management system of your distribution or third-party tools ( rbenv and RVM ). I think it's a disservice to recommend to people as a default. I don't know if they've fixed their performance issues or there are just very different ways to measure performance, in other benchmarking it's done very poorly, as other comments below suggest too. It is common because it comes with Ruby, and also many of the other gems run on it. It is perhaps the most common and the most cursed solution to making API requests. I also don't understand why httpparty is so popular. Ruby's standard library is already equipped with an HTTP client: the net/http gem. Although it's got some issues (pun intended) in it's maintenance/unclosed issues. I also don't know why these comparisons never include one of my favorites, HTTPClient. I think it comes from the days where there kind of was no good HTTP client so everybody chose something different and didn't trust their choice. I'm not sure how often that's a use case these days. Yes, if you are requesting a https url do this: require 'net/http' require 'net/https' require 'uri' uri URI.parse (url) http Net::HTTP.new (uri.host, uri.port) request Net::HTTP::Post.new (uri.requesturi) you need to set this field to true essl true http.verifymode OpenSSL::SSL::VERIFYNONE. I think the only reason to use faraday is it's actual motivation - to let you "wrap" other http clients, and switch back and forth between differnet clients without changing your calling code. I don't find a quick "do some metrics and write a blog post" super useful in navigating this landscape. I wonder if the author has used any of these in real projects over a long term, I think that's pretty invaluable in making recommendation/review, what you've actually run into in real use. It doesn't make sense to me to recommend it based on these kinds of metrics in this article. And you have the complexity/issues/bugs of whatever it wraps, plus it's own. It's performance will surely depend on what it wraps. I've become so frustrated in doing simple Security. Also see How to set SSLContext options in Ruby and How to set TLS context options in Ruby (like OpenSSL::SSL::SSLOPNOSSLv2). HTTParty, last time I checked it, was good enough for the "first (easy) 80% of work", but most of them are.įaraday is just a wrapper for other http clients, no? OpenSSL::SSL::SSLContext.new ('TLSv12client') At least that is what I'm using. The problem with Faraday is its complicated API for chunked reading (it requires to provide callbacks, while http.rb allows to just body.read(200) and that's it), and a bit of general "messiness" ( config.adapter fault_adapter anyone?.) = HTTPLibrary.new('') and then has a sweet spot with exactly this problem, plus a lot of "battery-included middleware", so (again, for API clients), you can build a sophisticated object with error processing, response parsing, and whatnot, and then just get('/endpoint') and have data ready to consume. I actually like HTTP.rb's API more, but they still can't make a decision about "base URL" API, which is quite valuable for API wrappers, e.g. For complicated use cases, we (in pany) ended up using Faraday (most of the time), with a fallback to http.rb in some cases.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |