RxRequester icon indicating copy to clipboard operation
RxRequester copied to clipboard

Add interceptors to RxRequester

Open AbanoubWagdyy opened this issue 5 years ago • 1 comments

Hi , I am just wanna asking about how to add different interceptors to client based on each screen have ? for example : 1-Login Screen : does not need ay custom interceptors 2-HomeScreen : It is based on token received from login screen ,so i need to add access token to header in get homepage content

How can i do this using RxRequester?

AbanoubWagdyy avatar Dec 15 '19 14:12 AbanoubWagdyy

Hi Abanoub,

Thanks for your question.

Adding Interceptors is out of the scope of RxRequester. You can add any interceptors using okhttp3.Interceptor as regular , for example:

class TokenInterceptor() : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        var request = chain.request()
        request = request.newBuilder()
                .addHeader("Authorization", "TOKEN")
                .build()
        return chain.proceed(request)
    }
}

// Add Interceptor
val builder = OkHttpClient.Builder()
                .addInterceptor(TokenInterceptor())
                .build()

The library just handles Retrofit errors and other errors, BUT doesn't apply any network configurations.

ShabanKamell avatar Dec 15 '19 17:12 ShabanKamell