In the retrofit adapter i have used a base Url for all my calls. so:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com")
.build();
GitHubService service = retrofit.create(GitHubService.class);
Lets say the above is my code, all my calls now use that baseUrl. But for one particular call, i want to change the base url, I dont want to create another rest adapter for this,as its just for testing locally. Can i change the end points in the interface possibly to not use the baseurl , or is there a annotation to supply my own base url ?
For latest Retrofit library, you can simply use singleton instance and change it with retrofitInstance. newBuilder(). baseUrl(newUrl) . No need to create another instance.
First, remove your prefix: api/v1/ as it only sets-up a global prefix, which is not what you want. Method 1 - via php: Add #[ApiResource(routePrefix: '/v1')] in your Book entity class: #[ApiResource(routePrefix: '/v1')] class Book { //... }
Retrofit is a type-safe REST client for Android, Java and Kotlin developed by Square. The library provides a powerful framework for authenticating and interacting with APIs and sending network requests with OkHttp. See this guide to understand how OkHttp works.
you can use the @Url
annotation to provide the full complete url. E.G.
@GET
Call<GitHubUser> getUser(@Url String url);
In retrofi2 the path in @GET overrides the base URL.
@GET("https://someurl/api/supermarkets")
Observable<List<TechIndex>> getTechIndexList();
The request will be send to "someurl/api/.." no matter what base url is. Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With