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.
- ruby on rails - about deploying apps using s3 function
- ruby - [rails] i can't bundle install on my macbook
- ruby on rails - routing error when pressing rails submit button
- ruby on rails 5 - determining column type boolean
- ruby on rails 6 - user information is not updated
- ruby on rails - activerecord :: recordnotfound in observationscontroller # edit couldn't find observation with'id' = 2
- ruby on rails 5 - if you get stuck in the required input, you don't want to see other validations
- ruby on rails 6 - after updating, it becomes no route matches [post] "/ posts/2/edit"
- ruby on rails - i get an error when i log in
- ruby on rails - i want to save text information in rails
- ruby - rails json i want to get multiple resources at the same time
- ruby on rails - i want to be able to search the data from the controller on the view side
- ruby on rails implementation of purchase history page when two are purchased at the same time
- ruby - [rails] i want to know the role of the aws access key in credentialsymlenc
- i want to fix a syntax error in ruby on rails
- ruby on rails - i get an error saying "activerecord :: recordnotfound in messagescontroller # index" "couldn't fi
- ruby - [rails] follow function cannot be implemented
- ruby on rails 5 - i want to introduce micropost search, but i get nomethoderror: undefined method `activated?'for nil: nilclass
- ruby - rails json i don't know how to write json conditional branch that is returned when selected
- ruby on rails - i want rails to display google map
- ruby - nameerror uninitialized constant drinkscontroller :: drinktag
- html - i want to display the view, but i get an error screen
- html - i want to display the posted prototype using collection
- ruby - i entered secret_key_base, but http error 500 cannot be resolved
- ruby - i want to change the way of arranging the hash value data obtained from the table
- ruby - i want to output csv with narrowed down conditions with rails
- ruby - sprockets :: rails :: helper :: assetnotfound in posts # index i want to display the images saved in my computer
- ruby - i get an error with a single test code for a model
- ruby - the method defined in the model cannot be used
- ruby - unable to save comments in db (rails)