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
Drop the mutable base URL. #1652
Conversation
This was unsafe for switching between development and production backends. This is because requests that are triggered on a UI thread may be delayed in execution on a background thread. These could cause requests created for a development environment to be executed against a production environment, or vice-versa. Retrofit is the wrong layer for switching backends for load balancing or proximity. That can happen in an OkHttp interceptor instead.
Whoa… Well, you're right that it's not safe to change url in Retrofit, but OkHttp interceptor is not a great place for that even more because not only it has the same problem with delayed requests but also you can't understand that request is coming from Retrofit inside of the interceptor (analyzing stacktrace is not an option)… Imagine you also have non-REST requests to the api endpoint that you do through same OkHttp instance without Retrofit. Would you suggest to rebuild the |
That has always been the recommendation, yes. |
ok, thanks for confirmation. // Anyway, 👍 👍 for more immutability, though |
Yep. This new interceptor is the new best way to test with a mock webserver. |
in my case baseUrl contains a path segment. I don't see any other way than manually replace the old baseUrl with the new one... |
@jbaginski you can rewrite the URL however you like. One option is to extract out the path & query in an interceptor, and add those on to the base URL. |
thanks @swankjesse, I ended up manipulating a string directly. it's not the best solution but it works ;) |
This solution will affect @get (full path) @post (full path) and @url so that they can not work,try my solution: https://github.com/JessYanCoding/RetrofitUrlManager |
This was unsafe for switching between development and production
backends. This is because requests that are triggered on a UI thread
may be delayed in execution on a background thread. These could cause
requests created for a development environment to be executed against
a production environment, or vice-versa.
Retrofit is the wrong layer for switching backends for load balancing
or proximity. That can happen in an OkHttp interceptor instead.