Slick23
Slick23

Reputation: 5897

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?

Upvotes: 3

Views: 837

Answers (2)

Kai
Kai

Reputation: 491

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.

Upvotes: 4

Alexis
Alexis

Reputation: 4499

You may find useful this short article from Adam Wiggins, initial author of RestClient: http://adam.heroku.com/past/2008/8/8/ruby_libs_for_making_web/

I personally am using httparty in my project - this was choice of previous developer, but it works for me pretty well.

Upvotes: 4

Related Questions