LoginSignup
2
2

More than 3 years have passed since last update.

[Rails] gem jsonを使って、APIを叩く。

Last updated at Posted at 2021-01-21

今回は、weather APIにしました。(https://openweathermap.org/)

APIの取得方法

gem json
def home
    require 'net/http'
    require 'json'

    @url = 'http://api.openweathermap.org/data/2.5/weather?q=berlin,de&appid=ここにapikey。'
    @uri = URI(@url)
    @response = Net::HTTP.get(@uri)
    @output = JSON.parse(@response)
   end

output

<%= @output %>

です。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2