简体   繁体   中英

Rails HTTParty Getting Timeout::Error

I have an API centric application (/api/v1/users) it simply return all users restfully with JSON format.

My problem is, if I call that route on the controller, it returns "Timeout::Error" What is the problem?

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

Update

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

https://gist.github.com/4359591

Logs

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?

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. 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.

If you want to test your API, I would look at a client tool like eg Postman .

HTH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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