Home

Awesome

This repository has code of OkHttp Profiler and OkHttp Request Modifier Android Libraries

OkHttp Profiler Android Library

OkHttp Request Modifier Android Library

OkHttp Profiler Android Library

Video Instructions On Youtube

Video Instructions on

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.

Installation

  1. Install AndroidStudio Plugin plugin: OkHttp Profiler plugin
  2. Add library to app build.gradle file (module level):
implementation("io.nerdythings:okhttp-profiler:1.1.1")
  1. Add interceptors to your OkHttp client:
OkHttpClient
    val builder = OkHttpClient.Builder()
    if (BuildConfig.DEBUG) {
        builder.addInterceptor(OkHttpProfilerInterceptor() )
    }    
    val client = builder.build()
For Retrofit
    val builder = OkHttpClient.Builder()
    if (BuildConfig.DEBUG) {
        builder.addInterceptor( OkHttpProfilerInterceptor() )
    }    
    val client = builder.build()
    val retrofit = Retrofit.Builder()
            .client(client)
            .build()

Full Readme:

OkHttp Profiler library

OkHttp Request Modifier Android Library

Video Instructions On Youtube

Video Instructions on

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.

<img src="https://github.com/itkacher/OkHttpProfiler/blob/master/request_modifiers_activity.png?raw=true" width=250><img src="https://github.com/itkacher/OkHttpProfiler/blob/master/request_modifiers_add_new_modifier.png?raw=true" width=250>

Installation

  1. 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")
  1. Add interceptors to your OkHttp client:
For OkHttp
    val builder = OkHttpClient.Builder()
    if (BuildConfig.DEBUG) {
        builder.addInterceptor(OkHttpRequestModifierInterceptor(applicationContext))
    }    
    val client = builder.build()
For Retrofit
    val builder = OkHttpClient.Builder()
    if (BuildConfig.DEBUG) {
        builder.addInterceptor(OkHttpRequestModifierInterceptor(applicationContext))
    }    
    val client = builder.build()
    val retrofit = Retrofit.Builder()
            .client(client)
            .build()
  1. 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))
    }
}

Full Readme:

OkHttp Request Modifier library