Retrofit: How to setup a retrofit call to do automatic retries on a GET

Created on 30 Apr 2015  Â·  7Comments  Â·  Source: square/retrofit

For a GET operation, I want to be able to specify that retry it 3 times with a 500ms wait in between.

Is this already possible? If so, documentation will be quite helpful. Thanks.

Most helpful comment

What you describe is an application-level policy that must be implemented by the application. Retrofit exists solely as a mechanism for creating requests from high-level Java objects, executing them on the underlying HTTP client, and marshaling the response back to high-level Java objects.

Policy like what you describe is vast and subjective. Thus, it's very hard to implement in any useful way with a reasonable API so we simply choose not to. This policy is much easier to implement at the application level because it doesn't need to be generalized and it can use additional information from the response to affect policy.

All 7 comments

You'd probably do this through setting the HTTP client, I think OkHttp supports this. Also, ask things like this on StackOverflow, not as a bug on the project.

Sure. I created the issue to add the documentation to the retrofit page at http://square.github.io/retrofit/, or to implement the feature if it is worth doing. Go ahead and close the issue if neither is a possibility.

What you describe is an application-level policy that must be implemented by the application. Retrofit exists solely as a mechanism for creating requests from high-level Java objects, executing them on the underlying HTTP client, and marshaling the response back to high-level Java objects.

Policy like what you describe is vast and subjective. Thus, it's very hard to implement in any useful way with a reasonable API so we simply choose not to. This policy is much easier to implement at the application level because it doesn't need to be generalized and it can use additional information from the response to affect policy.

Or, as suggested, you could have an HTTP client transparently implement this. OkHttp's interceptors come to mind, but then such policy applies globally to every request made.

Ok, that makes sense. Thanks Jake and DSteve

@JakeWharton is it possible to re-execute a pre-defined Observable?

https://stackoverflow.com/questions/47619115/how-to-retry-a-consumed-observable?

Subscribe to it again.

On Sun, Dec 3, 2017, 10:06 AM Sami Khleaf notifications@github.com wrote:

@JakeWharton https://github.com/jakewharton is it possible to
re-execute a pre-defined Observable?

https://stackoverflow.com/questions/47619115/how-to-retry-a-consumed-observable
?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/square/retrofit/issues/828#issuecomment-348780550,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEduZDovU5csK22eIfbIeuj84OVUBks5s8rkDgaJpZM4EMvq8
.

Was this page helpful?
0 / 5 - 0 ratings