Ruby is all about simplicity. But even using Ruby you can find some solutions that will make your routine even simpler! Today we prepared something special for you. Excited? Excon is a simple HTTP 1.1 client for Ruby.
Excon was designed to be simple, fast and performant. It works great as a general HTTP client and is well suited to usage in API clients.
The easiest way to get started is by using one-off requests. Supported one-off request methods are
trace. Requests return a response object which has
For API clients or other ongoing usages, reuse a connection across multiple requests to share options and improve performance.
connection = Excon.new('http://geemus.com') get_response = connection.get post_response = connection.post(:path => '/foo') delete_response = connection.delete(:path => '/bar')
By default, each connection is non-persistent. This means that each request made against a connection behaves like a one-off request. Each request will establish a socket connection to the server, then close the socket once the request is complete.
You can make use of HTTP pipelining to improve performance. Instead of the normal request cycle. You can take advantage of this using the
requestsmethod, which takes an array of params where each is a hash like a request would receive and returns an array of responses.
Please find more detailed information here.
And some awesome news about one famous book you have to read. Meet ‘The Well-Grounded Rubyist‘. The 3rd edition.