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

Allowing base url to null until dynamically change it later #2161

Closed
1 task
TonyTangAndroid opened this issue Jan 20, 2017 · 2 comments
Closed
1 task

Allowing base url to null until dynamically change it later #2161

TonyTangAndroid opened this issue Jan 20, 2017 · 2 comments

Comments

@TonyTangAndroid
Copy link

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.

I am building a serverless app which does not know the base url until the users set it up. However, I am also using Dagger 2 to initialize the Retrofit RestAPI adapter when the application gets started before a user has an opportunity to configure the server base url. But Retrofit2 does not allow empty base url, which makes my app crash during the initialization of Dagger2. So far, I could resolve it by providing a dummy but valid http url and change it base url after the user configure the correct one. But this does not feel right. I am wondering whether there is a better solution or not?

Any suggestion will be appreciated.

@JakeWharton
Copy link
Collaborator

You can either defer initialization of the Retrofit instance until the URL is known, or you can use a placeholder like http://localhost/ and use an OkHttp interceptor to rewrite all URLs with this host to whatever value is configured.

@TonyTangAndroid
Copy link
Author

Thank you very much for the confirmation. I will try to use the delay initialization way.

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

2 participants