title: Connecting to web services using Rails (HTTP requests)?
body: <p>I am using Ruby on Rails 3 and I am trying to implement APIs to retrieve account information from a web service. That is, I would like to connect to a web service that has the Account class and get information from the <code>show</code> action routed at the URI <code>http://&lt;site_name&gt;/accounts/1</code>.</p>
  
  <p>At this time, in the web service <code>accounts_controller.rb</code> file I have:</p>
  
  <pre><code>class AccountsController &lt; ApplicationController
    def show
      @account = Account.find(params[:id])
  
      respond_to do |format|
        format.html
        format.js
        format.json { render :json =&gt; @account.to_json }
      end
    end
  end
  </code></pre>
  
  <p>Now I need some advice for connecting to the web service. In the client application, I should have a HTTP GET request, but here is my question: What is "the best" approach to connect to a web service making HTTP requests? </p>
  
  <p>This code in the client application works:</p>
  
  <pre><code>url = URI.parse('http://&lt;site_name&gt;/accounts/1.json')
  req = Net::HTTP::Get.new(url.path)
  res = Net::HTTP.start(url.host, url.port) {|http|
    http.request(req)
  }
  
  @output = JSON(res.body)["account"]
  </code></pre>
  
  <p>but, is the above code "the way" to implement APIs? </p>
  
  <p>Is it advisable to use third-party plugins and gems?</p>