Home>
I want to hear

I want to get data from an external web API with Ruby on Rails.
In the case of Ruby, it is implemented as follows, but is there an implementation method unique to Ruby on Rails?
As for the background of the question, I wonder if there are gem dotenv for Ruby and Ruby on Rails, and I use Rails when I make a Rails application.
If i have something like this, "I'll do this for Ruby on Rails!"

require 'net/http'
require 'uri'
require 'json'
class User
   attr_reader: userid
   def initialize (userid)
     @userid = userid
   end
   def name
       url = URI.parse ("https://example.api.com/")
       json = Net :: HTTP.get (url)
       user = JSON.parse (json)
       puts user ['attributes'] ['name']
   end
end
  • Answer # 1

    I think it's basically the same.

    I saw a part where I made HTTP requests several times at work, but it was the same way.