Let Retrofit support multiple baseUrl and can be change the baseUrl at runtime (以最简洁的 Api 让 Retrofit 同时支持多个 BaseUrl 以及动态改变 BaseUrl).
Let Retrofit support multiple baseUrl and can be change the baseUrl at runtime (以最简洁的 Api 让 Retrofit 同时支持多个 BaseUrl 以及动态改变 BaseUrl).
implementation 'me.jessyan:retrofit-url-manager:1.4.0' // When building OkHttpClient, the OkHttpClient.Builder() is passed to the with() method to initialize the configuration
OkHttpClient = RetrofitUrlManager.getInstance().with(new OkHttpClient.Builder())
.build(); public interface ApiService {
@Headers({"Domain-Name: douban"}) // Add the Domain-Name header
@GET("/v2/book/{id}")
Observable<ResponseBody> getBook(@Path("id") int id);
}
// You can change BaseUrl at any time while App is running (The interface that declared the Domain-Name header)
RetrofitUrlManager.getInstance().putDomain("douban", "https://api.douban.com"); // BaseUrl configured in the Domain-Name header will override BaseUrl in the global setting
RetrofitUrlManager.getInstance().setGlobalDomain("your BaseUrl");
Copyright 2017, jessyan
根据 Apache 许可证第 2.0 版 (以下简称"许可证") 许可
除符合许可条款外,您不得使用此文件。
[ ](https://bintray.com/jessyancoding/maven/retrofit-url-manager/1.4.0/link)
[ ](https://travis-ci.org/JessYanCoding/RetrofitUrlManager)
[ ](https://android-arsenal.com/details/1/6007)
[ ](https://developer.android.com/about/versions/android-2.3.html)
[ ](http://www.apache.org/licenses/LICENSE-2.0)
[ ](https://www.jianshu.com/u/1d0c0bc634db)
[ ](https://shang.qq.com/wpa/qunwpa?idkey=7e59e59145e6c7c68932ace10f52790636451f01d1ecadb6a652b1df234df753)
[中文说明](README-zh.md)
[**Framework analysis 1**](http://www.jianshu.com/p/2919bdb8d09a)
[**Framework analysis 2**](https://www.jianshu.com/p/35a8959c2f86)
[**More complete sample**](https://github.com/JessYanCoding/ArmsComponent)暂无开放 Issues,或尚未同步最近议题。