Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit - Multiple endpoints with same RestAdapter

I would like to know how to create a RestAdapter that can switch between two endpoints. Currently in my app, the RestAdapter is created in the Application class(singleton). I am looking for a way to have different endpoints without actually creating multiple RestAdapter.

like image 639
amalBit Avatar asked Jan 07 '15 09:01

amalBit


1 Answers

Retrofit 1 calls Endpoint for each request (no cache), to you just need to extend Retrofit.Endpoint with some setter and pass this Endpoint when your creating the RestAdapter :

Endpoint mDynamicEndpoint = new DynamicEndpoint("http://firstdomain.fr");
RestAdapter restAdapter = new RestAdapter.Builder()
    .setEndpoint(mDynamicEndpoint)
    .build();

mDynamicEndpoint.setBaseUrl("http://yourdomain.com");

Possible duplicate : Dynamic Paths in Retrofit

like image 194
Hugo Gresse Avatar answered Oct 11 '22 07:10

Hugo Gresse