LoginSignup
2
0

More than 3 years have passed since last update.

RubyでAPIを簡単に取得する(クライアント側)

Last updated at Posted at 2019-07-22

Qiitaに載っているAPIの取得方法がどれも初めて利用するにはわかりずらい気がするので,必要不可欠なコードだけで叩く.

sample.rb
require 'net/http'
require 'uri'
require 'json' #jsonで返って来ないなら必要ない

uri = URI.parse("URL")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true #http通信だったらいらない
req = Net::HTTP::Post.new(uri.path)
res = http.request(req)
item = res.body #これ忘れること多いです
hash = JSON.parse(item) #jsonで返って来ないなら消してください.

これをコピペすれば動きます.

2
0
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
0