How to use external API in Ruby in Rails

You can use gem for calling REST APIs in ruby.

Also, if you want to find any ruby gem for any purpose you can have a look at this.

You can have a look at this to get company details.


You can use Net::HTTP to call APIs in Ruby on Rails.

  uri = URI(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(uri.path, {'Content-Type' => 'application/json'})

  request.body = {} # SOME JSON DATA e.g {msg: 'Why'}.to_json

  response = http.request(request)

  body = JSON.parse(response.body) # e.g {answer: 'because it was there'}

http://ruby-doc.org/stdlib-2.3.1/libdoc/net/http/rdoc/Net/HTTP.html