1

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

Seyhun Akyürek
  • 851
  • 9
  • 17

1 Answers1

3

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 e.g. Postman.

HTH.

nathanvda
  • 49,707
  • 13
  • 117
  • 139
  • Yes, it is correct. So tested my API with Postman extension and also with rails's console everything just works. How can I use multi processes for using in same application? – Seyhun Akyürek Dec 22 '12 at 16:50
  • While this could be possible, if you install apache/nginx and user passenger for instance, it is a lot of overhead. I do not understand why you would want to do that? It is a scenario heading for troubles. Because each single request will take up two requests of your server. Why not just call the code directly? – nathanvda Dec 22 '12 at 16:56
  • Because I'm building a web/mobile hybrid application, two of them sharing same API – Seyhun Akyürek Dec 22 '12 at 19:14
  • its not working on webrick/unicorn/thin servers, so running application on passenger/nginx module solved the problem, thanks. – Seyhun Akyürek Dec 22 '12 at 22:23