Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Net:Http and third-party library for making API calls in Rails/Ruby?

I came across this: https://github.com/archiloque/rest-client ...and it seems fairly simple and straight forward. But, working with third-party APIs is new to me, so I'm not sure what's important in a library and most of all, which is easiest to use.

Does rest-client offer any advantage over the standard Net::Http?

I also found https://github.com/jnunemaker/httparty, though it doesn't seem to be as well documented as rest-client or, even this one: https://github.com/dbalatero/typhoeus. Are they better than the included standard?

Any thoughts, suggestions?

like image 209
Slick23 Avatar asked Jan 27 '26 12:01

Slick23


1 Answers

Net::HTTP is meant to be a low level library for accessing networked resources. The third-party APIs make up for some of the difficulties that you'd otherwise have to handle yourself. To name a few:

  • Handling redirect codes
  • Implementing multipart file uploads
  • Storing cookies between requests
  • HTTP exception handling
  • Parsing responses (HTML, JSON, etc.)
  • Managing authentication/SSL on secure sites

In general, the authors of those libraries have taken extra care to make their API easy to use compared to Net::HTTP.

Also, I've found Mechanize to be a more complete solution for my needs than rest-client. For example, with rest-client you will still have to implement storing cookies between requests and handling redirects on POST requests.

like image 128
Kai Avatar answered Jan 30 '26 03:01

Kai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!