开发者

Wrap a foreign API into a Ruby class

开发者 https://www.devze.com 2022-12-18 00:00 出处:网络
I use HTTParty to consume a foreign API, but how can I convert the response into a Rub开发者_Python百科y class or Rails model?It is going to depend on the output of your API. If the output is JSON, yo

I use HTTParty to consume a foreign API, but how can I convert the response into a Rub开发者_Python百科y class or Rails model?


It is going to depend on the output of your API. If the output is JSON, you can use the built-in Rails JSON parsing. If the output is XML in a Rails-friendly format, you may be able to use the built-in object-to-xml conversion tools. Otherwise, you may need to create your mapping explicitly.


If the response is XML Nokogiri or ROXML come in handy. An alternative to ROXML would be Happymapper.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号