OkHttp Profiler Android Library
OkHttp Request Modifier Android Library
Video Instructions On Youtube
The OkHttp Profiler plugin can show requests from the OkHttp library directly in the Android Studio tool window. It supports the OkHttp v3 (http://square.github.io/okhttp/) and the Retrofit v2 (https://square.github.io/retrofit/)
You can debug OkHttp request or response headers, inspect the JSON as a tree, as a plain text etc. And you can easily create a Java/Kotlin model from the data. Just click the right mouse button on a root element of the tree (or any other), choose Java or Kotlin, and select a folder for a new file in the project.
- Install AndroidStudio Plugin plugin: OkHttp Profiler plugin
- Add library to app
build.gradle
file (module level):
implementation("io.nerdythings:okhttp-profiler:1.1.1")
- Add interceptors to your OkHttp client:
val builder = OkHttpClient.Builder()
if (BuildConfig.DEBUG) {
builder.addInterceptor(OkHttpProfilerInterceptor() )
}
val client = builder.build()
val builder = OkHttpClient.Builder()
if (BuildConfig.DEBUG) {
builder.addInterceptor( OkHttpProfilerInterceptor() )
}
val client = builder.build()
val retrofit = Retrofit.Builder()
.client(client)
.build()
Video Instructions On Youtube
Request Modifier is a new Android library designed to provide developers with an easy way to customize HTTP responses. By adding this library into your project, you gain the ability to modify response bodies and response codes dynamically.
- Add libraries to app
build.gradle
file (module level):
releaseImplementation("io.nerdythings:okhttp-requests-modifier-no-op:1.0.2")
debugImplementation("io.nerdythings:okhttp-requests-modifier:1.0.2")
- Add interceptors to your OkHttp client:
val builder = OkHttpClient.Builder()
if (BuildConfig.DEBUG) {
builder.addInterceptor(OkHttpRequestModifierInterceptor(applicationContext))
}
val client = builder.build()
val builder = OkHttpClient.Builder()
if (BuildConfig.DEBUG) {
builder.addInterceptor(OkHttpRequestModifierInterceptor(applicationContext))
}
val client = builder.build()
val retrofit = Retrofit.Builder()
.client(client)
.build()
- Call
OkHttpProfilerSettingsActivity
from your code
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxSize(),
) {
Button(onClick = ::openSettings) {
Text(text = stringResource(id = R.string.open_modifier))
}
}
}
}
private fun openSettings() {
startActivity(OkHttpProfilerSettingsActivity.getIntent(applicationContext))
}
}