RetrofitUrlManager
介绍:
以最简洁的 Api 让 Retrofit 同时支持多个 BaseUrl 以及动态改变 BaseUrl.
运行效果:
使用说明:
Download
compile 'me.jessyan:retrofit-url-manager:1.0.5'
Initialize
// When building OkHttpClient, the OkHttpClient.Builder() is passed to the with() method to initialize the configuration
OkHttpClient = RetrofitUrlManager.getInstance().with(new OkHttpClient.Builder())
.build();
Step 1
public interface ApiService {
@Headers({"Domain-Name: douban}) // Add the Domain-Name header
@GET("/v2/book/{id}")
Observable<ResponseBody> getBook(@Path("id") int id);
}
Step 2
// 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");
If you want to change the global BaseUrl:
// BaseUrl configured in the Domain-Name header will override BaseUrl in the global setting
RetrofitUrlManager.getInstance().setGlobalDomain(“your BaseUrl”);
已下载
0