Ruby’s built-in library: Net/HTTP and gems that powers Net/HTTP:
- Multipart::Post—streamy multipart form post capability
- Net::HTTP::Persistent—Persistent support
REST Client, httparty, and Nestful.
curb, EM-HTTP-Request, Patron, and Typhoeus.
EM-Synchrony, excon, Faraday, httpclient, HTTPX, and net-http2.
There are probably many more I did not know about, what should we choose?
- shrine uses HTTP
- Octokit.rb uses Faraday
Stripe Ruby API client is
...Don’t worry, it’s very easy to evaluate.
Easy to use API
Fast (Keep-Alive, HTTP/2 Connection Coalescing)
Low memory usage
Network usage ((de)compression of request/response)
So you send smaller request / receive small response = Less network usages.
Concurrent support by protocol (HTTP pipeline, HTTP/2 multiplex)
Less dependencies to keep up; Less memory; If you’re building a client of a service, you probably want to have no dependency in order to have as many users as possible.
Possible to fit all scenarios you need
We want one gem to rule them all.
Let’s rule out gems that do not comes with what we want:
httparty does not have Keep-Alice support (you need persistent_httparty to keep the party alive). REST Client uses too much memory and currently the slowest.
EM-* also requires multiple gems.
Net/HTTP’s API is not very easy to use.
Now we still have many libraries to choose from. How about we consider some of HTTP/2 features? Now we left with only HTTPX...
HTTP/2 & concurrent requests
The concurrency are done via HTTP protocol’s features: HTTP/2 multiplex & HTTP Pipeline support without you do any work, same API. It is based on a plugin-in system, you only use what you need, lightweight.
The documentation is simple
All HTTP features are well tested by httpbin.
ALPN support to reduce latency (if you use HTTPS resolver for DNS)
Alt-Svc support that directs you to the right/closest server
See HTTPX wiki.