How can i connect to a separate server and parse its JSON response?

前端 未结 2 1006
谎友^
谎友^ 2021-01-26 13:02

i need to connect to another server we manage and have it\'s results (in JSON format) processed by rails... how can I do it ?

Thanks!

2条回答
  •  耶瑟儿~
    2021-01-26 13:30

    You can use something like ActiveResource as a model if you like that kind of interface:

    class Thing < ActiveResource::Base
      self.site = "http://api.example.com:3000/"
      self.format = :json
      self.element_name = "thing"
    end
    

    This might be more than you need, though, as often Net::HTTP and the JSON library will do the job.

提交回复
热议问题