android - how use one retrofit and okhttp object with multiple api -
assume app communicate multiple end point api difference base url , header best way use retrofit , okhttp application api , third party api google , forsqure , facebook..
can use 1 retrofit , okhttp object handle requests? use intercept add rest application okhttp , how can use object other third party api?
okhttpclient provideokhttpclient(string token) { okhttpclient.builder clientbuilder = new okhttpclient.builder(); clientbuilder.addinterceptor(chain -> { request original = chain.request(); request.builder requestbuilder = original.newbuilder() .header("accept", "application/json") .header("content-type", "application/x-www-form-urlencoded") .header("x-token", token) .method(original.method(), original.body()); request request = requestbuilder.build(); return chain.proceed(request); }); clientbuilder .connecttimeout(1,timeunit.minutes) .writetimeout(2, timeunit.minutes); return clientbuilder.build(); }
i think basic way in intercepter check if request third party or application rest call? correct? or there better way handle request?
Comments
Post a Comment