Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low-level HTTP calls with Retrofit adapters #3750

Open
1 task
quilin opened this issue Jun 24, 2022 · 2 comments
Open
1 task

Low-level HTTP calls with Retrofit adapters #3750

quilin opened this issue Jun 24, 2022 · 2 comments

Comments

@quilin
Copy link

quilin commented Jun 24, 2022

What kind of issue is this?

  • Feature Request. Start by telling us what problem you’re trying to solve. Often a solution
    already exists! Don’t send pull requests to implement new features without first getting our
    support. Sometimes we leave features out on purpose to keep the project small.

So we were implementing the fault-tolerance system for our Android application based on storing the low-level request data in SQLite and process the stored requests in a background. After consideration we came to the point where we will only store the method, url and body of the request, relying on our interceptors to add the API/Auth tokens.

We do not want to store the data that will rely on our code, so it is not okay for us to use the retrofit annotated API-services and instead we require low-level calls, such as:

val request = Request.Builder()
   .url(queuedRequest.url)
   .method(queuedRequest.method, queuedRequest.body.toRequestBody())

val response = retrofit.callFactory().newCall(request).execute()

It does the thing and it works correctly with all the interceptors that enrich the request with the tokens. However, we also use retrofit-specific CallAdapters we run into the issue. In our case we only use the Retry policy from resilience4j.retrofit and it is being bootstrapped by Retrofit.Builder().addCallAdapterFactory(RetryCallAdapter.of(apiRetry)). So when we call the callFactory() it returns the OkHttp low-level call factory that is oblivious to any call adapters that we have. It is not the biggest deal and we work it around with

val supplier = Retry.decorateSupplier(RemoteDataModule.apiRetry) {
   val response = retrofit.callFactory().newCall(request).execute()
   if (response.isSuccessful) {
      Response.success(response.code, response.body.toString())
   } else {
      Response.error(response.code, response.body!!)
   }
}

But of course it only looks okay-ish because we only use one call adapter, and, for example, no CircuitBreaker so far.

So the problem is - is there a way to make a low-level calls to the whole retrofit instance without using the annotated service? Is it a proper feature request?

Thanks in advance,
Best regards :)

@quilin
Copy link
Author

quilin commented Jul 12, 2022

Any updates here? I'm willing to make a PR for this feature, or if you can suggest a proper workaround, I'd be happy :)

@quilin
Copy link
Author

quilin commented Feb 10, 2023

Kind semi-year reminder :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant