Ruby RestClient教程
所有@代表自定义的变量
Require Gems:
require 'rest-client'
require 'json'
API url的信息可以从网上搜索到可以用的具体链接,按照API中给定的参数进行API请求
Method Get:
resposne = RestClient::Request.execute(method: :get, url: @url, user: @user, password: @password)
json = Json.parse(response)
Method Put or Post:
request = RestClient::Request.new(
:method => :put/:post
:url => @url
:user => @user
:password => @password
:headers => {
:Accept => "application/json"
:content_type => "application/json"
}
:payload => @json_format
)
response = request.execute