Русский | English

Пример обращения к RESTful API на Ruby:

require 'net/http'
require 'json'
USER_TOKEN = '?????'
HOST = 'http://ws-dss.com'
# Job creation preparing
uri = URI(HOST + "/ws_jobs.json")
req = Net::HTTP::Post.new(uri)
req['user-token'] = USER_TOKEN
req.set_form_data('ws_job[ws_method_id]' => 8, 'ws_job[input]' => '{"team": 20150310700}')
res = Net::HTTP.start(uri.hostname) {|http|http.request(req)}
if !res.is_a?(Net::HTTPSuccess) # error check
  puts "Error #{res}\n#{res.body}"
  exit(1) 
end
h = JSON.parse(res.body)
ws_job_id = h["id"]
puts "Job was created! id = #{ws_job_id}"
i = 0
# if job was not completed we must wait
while h["output"].nil? and i < 100 do
  i += 1
  puts i
  sleep(i*5)
  uri = URI(HOST + "/ws_jobs/#{ws_job_id}.json")
  req = Net::HTTP::Get.new(uri)
  req['user-token'] = USER_TOKEN
  res = Net::HTTP.start(uri.hostname) {|http|http.request(req)}
  if !res.is_a?(Net::HTTPSuccess)
    puts "Error #{res}\n#{res.body}"
    exit(1) 
  end
  h = JSON.parse(res.body)
end
puts "i = #{i} output =\n#{h["output"]}"

Пример обращения к RESTful API на VBA в Excel:

    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    URL = Range("ws_job")
    objHTTP.Open "PATCH", URL, False
    objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
    objHTTP.setRequestHeader "user-token", Range("token")
    objHTTP.send ("ws_job[input]=" + s)
    s = objHTTP.responseText
    
    Application.Wait Now + #12:00:03 AM#
    
    objHTTP.Open "GET", URL, False
    objHTTP.setRequestHeader "user-token", Range("token")
    objHTTP.send
    s = objHTTP.responseText
    
    Set Json = JsonConverter.ParseJson(s)
    
    a = Split(Json("output"), vbLf)
    i = 1
    For Each r In a
        Worksheets("trace").Cells(i, 1) = r
        i = i + 1
    Next r