Skip to content

jkyeo/okhttp-basicparamsinterceptor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

e354e3b · Apr 27, 2017

History

14 Commits
Apr 7, 2016
Dec 26, 2016
Apr 7, 2016
Apr 7, 2016
Apr 7, 2016
Apr 7, 2016
Apr 7, 2016
Apr 7, 2016
Apr 7, 2016
Apr 7, 2016
Apr 7, 2016
Apr 7, 2016

Repository files navigation

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();