简体   繁体   English

Rails HTTParty获取超时::错误

[英]Rails HTTParty Getting Timeout::Error

I have an API centric application (/api/v1/users) it simply return all users restfully with JSON format. 我有一个以API为中心的应用程序(/ api / v1 / users),它只是简单地以JSON格式返回所有用户。

My problem is, if I call that route on the controller, it returns "Timeout::Error" What is the problem? 我的问题是,如果我在控制器上调用该路由,则返回“Timeout :: Error”有什么问题?

class BaseController < ApplicationController
  def index
    return HTTParty.get('http://localhost:3000/api/v1/users').body
  end
end

Update 更新

  • users_controller.rb (/api/v1/users) users_controller.rb(/ api / v1 / users)
  • application_controller.rb application_controller.rb

https://gist.github.com/4359591 https://gist.github.com/4359591

Logs 日志

http://pastie.org/5565618 http://pastie.org/5565618

If I understand correctly, you have an API end-point, at /api/v1/users , and your BaseController#index is calling that method? 如果我理解正确,你有一个API端点,在/api/v1/users ,你的BaseController#index正在调用该方法?

If that is correct, inside the same rails process, and you are testing in development mode (as I can tell from your url), then you only have a single process running, which can only handle a single request at once. 如果这是正确的,在相同的rails进程中,并且您正在开发模式下进行测试(我可以从您的url中进行测试),那么您只能运行一个进程,它只能一次处理一个请求。 So if you start a request to BaseController#index , it will start another request to your own test-server, which is busy, and it will just wait until it times out. 因此,如果您启动对BaseController#index的请求,它将向您自己的测试服务器启动另一个请求,该服务器正忙,并且它将等待它超时。

If you want to test your API, I would look at a client tool like eg Postman . 如果你想测试你的API,我会看一下像Postman这样的客户端工具。

HTH. HTH。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM