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 GEO下载数据的处理报错 :函数‘Meta’标签‘"data.frame"’找不到继承方法,如何解决?
      • ¥15 DLNM模型是否可以用二分类变量作为y变量
      • ¥15 android object box 一个实体多个表怎么写
      • ¥15 temux 启用docker 服务失败
      • ¥15 Flask 使用celery发送邮件出现‘目标计算机积极拒绝‘
      • ¥60 老人用的sd卡在手机里面不知道操作了什么,导致图片和视频变成了文件,取下sd卡连接电脑就是图中的样子,后缀改为.jpg才可以,需要用系统的画图软件才能打开,文件属性还是文件,有没有批量操作的解决办法
      • ¥15 超时跳出方法代码的返回值问题
      • ¥15 汇编语言程序设计设计,ascii码求数,再求数的BCD码
      • ¥30 Mask rcnn训练自己的数据集出现问题!
      • ¥20 研究人工智能时的几个问题