Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby Equivalent of Python Requests Library (HTTP Client)

Tags:

http

ruby

There is a library in Python that I love called "Requests". Requests is a HTTP client build on urllib3. "requests doc".

I am looking for something similar in Ruby. Basically what I need is:

  • Upload files support (multipart/form-data).
  • Easy get/post.
  • Cookies can be passed from a response object to a request object (build manually login script).
  • Stable and Flexible.
  • Sessions support (to not have to handle cookies manually if we don't have too).

I've looked at Typhoeus, but the code example in the home page doesn't work; they have moved code along and the get method is not longer directly accessible like that, so it's not starting well. Curb seems nice and I like cURL, there is also rest-client, which seems popular, and em-http seems pretty fast according to benchmark. There is a also Patron and curb-fu, which I haven't have the time to try. And, of course, Net:HTTP. But, it doesn't seem to have a mainstream solution that everyone points to.

I think a lot of people have been in my situation and I wonder what they have choosen and why?

like image 498
Hartator Avatar asked Oct 30 '12 04:10

Hartator


People also ask

What Python library would you use to serve HTTP requests?

In this article, you will learn about the Python Requests library, which allows you to send HTTP requests in Python.

Is requests a built in Python library?

Requests is one of the most popular Python libraries that is not included with Python.

What is HTTP client library?

The HTTP Client library provides a basic API through which HTTP requests can be created and executed from within your model.


2 Answers

Here is a feature matrix featuring a selection of HTTP clients for Ruby.

https://bit.ly/RubyHTTPClients

The author of the comparison is the author of httpclient, but from the looks of it the comparison is fair.

For a more narrative style with some explanation of the matrix, see http://www.slideshare.net/HiroshiNakamura/rubyhttp-clients-comparison from the same author.

The comparison comes out partly in favor of httpclient, which I can also recommend. Simple, featureful, compatible with all Ruby platforms and performant. Better cookie support than anything else out there, but the presentation mentions that cookies may leak from one (malevolent) site to another if you use the same client object. Don't know if this is still true.

like image 168
clacke Avatar answered Sep 20 '22 16:09

clacke


There is https://github.com/cyx/requests, which is exactly what the question is asking for, a port of the requests lib from python.

like image 43
f-3r Avatar answered Sep 19 '22 16:09

f-3r