An open API service indexing awesome lists of open source software.

https://github.com/imsankalp/react-native-network-tools

A developer tool to inspect network requests in react native application
https://github.com/imsankalp/react-native-network-tools

developer-tools expo react-native tanstack-query

Last synced: 2 months ago
JSON representation

A developer tool to inspect network requests in react native application

Awesome Lists containing this project

README

          

# react-native-network-tools

A powerful React Native library that allows you to track and inspect all network requests in your app. Perfect for debugging, monitoring, and understanding your app's network behavior.

## Features

- 🔍 **Automatic Request Tracking**: Captures all OkHttp network requests automatically
- 🐛 **Debug-Only**: Zero overhead in production builds (only active in debug mode)
- 📊 **Detailed Information**: Captures request/response headers, bodies, timing, and errors
- 💾 **In-Memory Storage**: Stores up to 100 recent requests with automatic cleanup
- 🔒 **Thread-Safe**: Built with concurrent data structures for reliability
- ⚡ **Easy Integration**: Simple API with minimal setup required

![](Screen_recording_20260204_002905.mp4)

## Installation

```sh
npm install react-native-network-tools
# or
yarn add react-native-network-tools
```

If you use Expo Development Builds, add the plugin to `app.json`:

```json
{
"expo": {
"plugins": ["react-native-network-tools"]
}
}
```

## Quick Start

### 1. Configure OkHttpClient (Android)

Add the interceptor to your `MainApplication.kt`:

```kotlin
import com.networktools.NetworkToolsManager
import okhttp3.OkHttpClient

class MainApplication : Application(), ReactApplication {

override fun onCreate() {
super.onCreate()

NetworkingModule.setCustomClientBuilder(
object : NetworkingModule.CustomClientBuilder {
override fun apply(builder: OkHttpClient.Builder) {
NetworkToolsManager.addInterceptor(builder)
}
}
)

// rest code
}
}
```

### 2. Wrap Your App with NetworkMonitorProvider

```typescript
import { NetworkMonitorProvider } from 'react-native-network-tools';

function App() {
return (

{/* Your app code */}

);
}
```

### 3. View Network Requests

```typescript
import * as NetworkTools from 'react-native-network-tools';

// Get all requests
const requests = NetworkTools.getAllRequests();

// Get specific request
const request = NetworkTools.getRequestById('request-id');

// Clear all requests
NetworkTools.clearAllRequests();

// Get request count
const count = NetworkTools.getRequestCount();
```

## API Reference

### `getAllRequests(): NetworkRequest[]`
Get all captured network requests.

### `getRequestById(id: string): NetworkRequest | null`
Get a specific network request by its unique ID.

### `clearAllRequests(): void`
Clear all stored network requests from memory.

### `getRequestCount(): number`
Get the total count of stored network requests.

### `isNativeNetworkToolsAvailable(): boolean`
Detect if the native module is available at runtime.

### `getNetworkToolsRuntime(): 'turbo' | 'legacy' | 'unavailable'`
Detect whether the module is running over TurboModule, legacy bridge, or is unavailable.

## NetworkRequest Type

```typescript
interface NetworkRequest {
id: string;
url: string;
method: string;
requestHeaders: Record;
requestBody?: string;
requestTime: number;
responseCode?: number;
responseHeaders?: Record;
responseBody?: string;
responseTime?: number;
duration?: number;
error?: string;
}
```

## Build Configuration

The library automatically enables tracking only in debug builds. You can customize this behavior:

```gradle
buildTypes {
debug {
buildConfigField "boolean", "NETWORK_TOOLS_ENABLED", "true"
}
staging {
buildConfigField "boolean", "NETWORK_TOOLS_ENABLED", "true"
}
release {
buildConfigField "boolean", "NETWORK_TOOLS_ENABLED", "false"
}
}
```

## Advanced Usage

For detailed setup instructions, custom configurations, and advanced usage patterns, see the [Setup Guide](docs/SETUP_GUIDE.md).
For Expo validation, see the [Expo smoke test](docs/EXPO_SMOKE_TEST.md).

## Platform Support

| Platform / Runtime | Status | Notes |
| --- | --- | --- |
| React Native Android (New Architecture) | ✅ Supported | TurboModule path |
| React Native Android (Old Architecture) | ✅ Supported | Legacy bridge fallback |
| Expo Development Build + Prebuild (Android) | ✅ Supported | Use config plugin |
| Expo Go | ❌ Not supported | Native interception requires a dev build |
| iOS | 🚧 In progress | Not yet implemented end-to-end |

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)