Cha*_*rge 4 api ruby-on-rails ruby-on-rails-4
我需要在我的应用程序中使用外部API才能获得公司信息.从未在Ruby中使用过API,我不知道从哪里开始.也许有一个宝石,但我发现2 API返回给我JSON:https://datainfogreffe.fr/api/v1/documentation和https://firmapi.com/(他们在法国抱歉) .有人有一个很好的教程或提示来帮助我开始吗?
最后的需求是通过提供公司ID来检索公司数据.
Gok*_*l M 14
您可以使用Net::HTTP
Ruby on Rails 调用 API。
uri = URI(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.path, {'Content-Type' => 'application/json'})
request.body = {} # SOME JSON DATA e.g {msg: 'Why'}.to_json
response = http.request(request)
body = JSON.parse(response.body) # e.g {answer: 'because it was there'}
Run Code Online (Sandbox Code Playgroud)
http://ruby-doc.org/stdlib-2.3.1/libdoc/net/http/rdoc/Net/HTTP.html
归档时间: |
|
查看次数: |
4519 次 |
最近记录: |