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 - when i execute the rails s command, the message run `bundle install` to install missing gems is displayed and it
- ruby - rails transaction does not execute the process after rescue
- ruby - the last db setting doesn't work when deploying rails app on aws
- ruby - [rails] i want to create an image link using the url of the image output using active storage
- ruby - rails causes activerecord :: recordnotfound and routing error at the same time
- ruby on rails - after installing devise on rails6, routing error occurs, so i want to eliminate it
- ruby on rails - i want to resolve rails nameerror
- ruby on rails - i can't update rubygems
- ruby - about "activemodel :: unknownattributeerror" of rails
- ruby on rails 6 - rails6 activerecord :: recordinvalid in userscontroller # update
- ruby on rails 6 - i changed the project name of rails, but it became inaccessible
- ruby - [rails] i want to change the argument of link_to using conditional branching
- ruby on rails - i want to resolve rails wrong number of arguments
- ruby on rails - i want to jump to the action of another controller with render
- ruby on rails - heroku: how to check the database_url used for regular backup
- ruby on rails 5 - i want to update the received parameters with nil
- ruby on rails - it is not saved in the database after registering the product
- ruby on rails - mvc rails
- ruby on rails - rails6 rspec model run-time error nomethoderror: undefined method `valid?'for nil: nilclass
- ruby - rails tutorial chapter 2 (6th edition)
- ruby - passing variables using render partial
- ruby - gem devise (top page (login form input)) → list screen
- ruby - i get an error with the rails new command
- ruby - implementation of friendly forwarding
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby - about rails controller new action
- ruby - rails page does not open
- [ruby] i'm having trouble with nomethoderror
- ruby - [search function] acquisition of products associated with users
- ruby - even if each statement is used, the contents of the db cannot be displayed in order and an error occurs