How to set timeout in RestClient gem in Ruby?
Asked Answered
M

1

42

I am using RestClient gem by making get call to the server through it. The question is how do I set the timeout from client side.

RestClient.get "http://127.0.0.1:7819/tokenize/word/stackoverflow"

I want to set it to 10 seconds.

Thanks in Advance!!

Marsipobranch answered 7/5, 2012 at 13:58 Comment(0)
C
68

You don't need to monkey patch anything. You can use RestClient::Request directly, like:

RestClient::Request.execute(:method => :get, :url => url, :timeout => 10, :open_timeout => 10)

But remember the worst case scenario is 20 seconds.

Check the other post answer https://mcmap.net/q/391852/-ruby-rest-client-make-it-never-timeout

Cumberland answered 21/8, 2012 at 14:21 Comment(3)
This should be the answer - I'm afraid that I must assert that monkey patches are evil due to the unintended side effects they have.Citify
nit: you don't have to specify both timeout and open_timeout if those two are same value. timeout value will be used for both read_timeout and open_timeout. github.com/rest-client/rest-client/blob/…Cle
When using RestClient::Resource, could try RestClient::Resource.new('http://slow', :timeout => 10)Afforest

© 2022 - 2024 — McMap. All rights reserved.