Nosy Inspect

Inspect network traffic in your mobile app. See outgoing requests and incoming responses, their timing, headers, response codes and most imporantly body.

Desktop app

First you need an desktop application to be able to connect to your device or emulator and see requests coupled together with their responses.

macOS (intel)macOS (apple)Windows

Integration

Andoird iOS React Native

Android

  1. Add dev dependency to build.gradle
    debugImplementation "dev.nosytools:inspect:1.2.0"
  2. Use LoggingInterceptor when configuring OkHttpClient. Make sure it is not included for release builds.
    import dev.nosytools.inspect.LoggingInterceptor;
    
    // (...)
    
    OkHttpClient.Builder()
      .addInterceptor(LoggingInterceptor())
      .build()

iOS

Nosy Inspect is provided as a Swift Package for iOS.

  1. Select File > Add Package Dependency and enter following repository URL: https://github.com/kkosobudzki/nosy-ios
  2. Import NosyInspect in your AppDelegate.m file. Make sure it is imported only in debug mode. Last but not least, initialize it.
    #if DEBUG
    @import NosyInspect;
    #endif
    
    // (...)
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
      // (...)
                
      #if DEBUG
      [NosyInspect inspect];
      #endif
    
      // (...)
                
    }

React Native

To use Nosy Inspect in React Native applications, following changes in native parts requried.

Android

  1. Add dev dependency to android/app/build.gradle
    debugImplementation "dev.nosytools:inspect:1.2.0"
  2. Create HttpClientFactory.kt for debug variant to be sure it is not included for release builds. Let's add the file into android/app/src/debug/java/com/yourawesomeproject directory.
    package com.yourawesomeproject
    
    import com.facebook.react.modules.network.OkHttpClientFactory
    import com.facebook.react.modules.network.ReactCookieJarContainer
    import dev.nosytools.inspect.LoggingInterceptor
    import okhttp3.OkHttpClient
    import java.util.concurrent.TimeUnit
    
    class HttpClientFactory : OkHttpClientFactory {
    
        override fun createNewNetworkModuleClient(): OkHttpClient =
            OkHttpClient.Builder()
              .connectTimeout(0, TimeUnit.MILLISECONDS)
              .readTimeout(0, TimeUnit.MILLISECONDS)
              .writeTimeout(0, TimeUnit.MILLISECONDS)
              .cookieJar(ReactCookieJarContainer())
              .addInterceptor(LoggingInterceptor())
              .build()
    }

    Timeouts are set to 0 which is infinite. It is not required by Nosy Inspect but let you find and log long haning requests without them being killed.

  3. Create HttpClientFactory.kt for release variant. Let's add the file into android/app/src/release/java/com/yourawesomeproject directory.
    package com.yourawesomeproject
    
    import com.facebook.react.modules.network.OkHttpClientFactory
    import com.facebook.react.modules.network.ReactCookieJarContainer
    import okhttp3.OkHttpClient
    import java.util.concurrent.TimeUnit
    
    class HttpClientFactory : OkHttpClientFactory {
    
        override fun createNewNetworkModuleClient(): OkHttpClient =
            OkHttpClient.Builder()
              .connectTimeout(1, TimeUnit.MINUTES)
              .readTimeout(1, TimeUnit.MINUTES)
              .writeTimeout(1, TimeUnit.MINUTES)
              .cookieJar(ReactCookieJarContainer())
              .build()
    }

    Feel free to modify timeouts to match your requirements. One minute seems a way too long for a production ready app.

  4. Use HttpClientFactory in onCreate() method inside application file (android/app/src/main/java/com/yourawesomeproject/MainApplication.java).

    package com.yourawesomeproject
    
    // (...)
    
    import com.facebook.react.modules.network.OkHttpClientProvider;
    
    // (...)
    
    @Override
    public void onCreate() {
      super.onCreate();
    
      // (...)
      
      OkHttpClientProvider.setOkHttpClientFactory(new HttpClientFactory());
    }

iOS

Nosy Inspect is provided as a Swift Package for iOS.

  1. Select File > Add Package Dependency and enter following repository URL: https://github.com/kkosobudzki/nosy-ios
  2. Import NosyInspect in your AppDelegate.m file. Make sure it is imported only in debug mode. Last but not least, initialize it.
    #if DEBUG
    @import NosyInspect;
    #endif
    
    // (...)
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
      // (...)
                
      #if DEBUG
      [NosyInspect inspect];
      #endif
    
      // (...)
                
    }