Consuming REST API Rails

痴心易碎 提交于 2019-12-11 05:39:43

问题


I've looked at this question but it's quite old and I feel there's now other alternatives to ARes.

Given that many people seem to think that ActiveResource is kind of outdated and heavyweight, I've looked at Api Smith, Her, Roar and of course ARes.

Which one of these gems would be the most reliable, and future proof alternative?


回答1:


Why not using lower level libraries like HTTParty or Faraday ? They will cover a lot of the ugly stuff for you (ssl, parsing/serializing jsons and XMLs, logging, adding headers...) and you'll keep complete control of the URLs and the management of data.




回答2:


I found that simply using open-uri and json is a viable option. Less boilerplate and more control / configurability.

Example:

@people = JSON.parse(open("http://api.people.com:3000/people").read, symbolize_names: true)



回答3:


Roar gem's purpose is to help you build and deserialize objects and it handles a several different JSON formats like JSON-API, JSON-HAL, etc, XML and it's fairly easy to extend the underlying Representable Gem ( forked from popular ROXML gem). Considering Roar is by far the most popular alternative to ARes, and is part of the much larger Trailblazer Ecosystem ( thou you can use it on it's own) - I would argue Roar is more "future proof". But I might be biased.



来源:https://stackoverflow.com/questions/13159314/consuming-rest-api-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!