Android part of the Android Studio(IntellijIDEA) OkHttp Profiler plugin
OkHttp Profiler Android Library
OkHttp Request Modifier Android Library
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.
build.gradle
file (module level):
implementation("io.nerdythings:okhttp-profiler:1.1.1")
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()
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.
| | | |———————————————————————————————————————-|——————————————————————————————————————————|
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")
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()
OkHttpProfilerSettingsActivity
from your codeclass 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))
}
}