weixin_33709219 2016-09-06 21:17 采纳率: 0%
浏览 81

Rails中的API调用

This feels like a dumb question, but the more I think about it the more confused I get: how (and where? Model? Controller?) do I make an API call in a Rails app?

I need to make a string of API calls, capture the returned data, save pieces of that data to a database, and then use that database info to make another API call. That repeats a couple times, building the data I need for the final API request (which winds up being a POST request, but I would probably need to save the "success" or "fail" message to the database too).

Typically, I use AJAX in my non-rails projects to APIs to get what I need...but those are more display-only situations, so I've never needed to save what the API returned. I think about 90% of my confusion stems from the fact that I'm trying to figure out how to make an AJAX call in a rails model, when really I should (somehow, and here is where my knowledge ends) be making an HTTP request in my model.

I may be missing something fundamentally about Ruby and/or Rails that allows me to make HTTP requests, so I would highly value any feedback/guidance on how to get started making these necessary API calls!

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog