A Basic Params Interceptor for okhttp3
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
basicparamsinterceptor
gradle/wrapper
.gitignore
BasicParamsInterceptor.iml
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

okhttp-basicparamsinterceptor

A Basic Params Interceptor for okhttp3.

Via this interceptor we can inject header, url-query and even body (post with "x-www-form-urlencoded" contentType) params into every http request in okhttp3.

Setup

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Step 2. Add the dependency

dependencies {
        compile 'com.github.jkyeo:okhttp-basicparamsinterceptor:v0.9'
}

Usage

BasicParamsInterceptor basicParamsInterceptor =
        new OkPublicParamsInterceptor.Builder()
                .addHeaderParam("device_id", DeviceUtils.getDeviceId())
                .addParam("uid", UserModel.getInstance().getUid())
                .addQueryParam("api_version", "1.1")
                .build();


OkHttpClient client = new OkHttpClient.Builder()
        .addInterceptor(basicParamsInterceptor)
        .build();