|
1 | | -# react-native-api-debugger |
| 1 | +# React Native API Debugger |
2 | 2 |
|
3 | | -API logger/visualizer for react native mobile application |
| 3 | +A comprehensive network request debugging tool for React Native applications. Monitor, inspect, and debug all your app's network requests with an intuitive overlay interface. |
| 4 | + |
| 5 | +[](https://www.npmjs.com/package/react-native-api-logger) |
| 6 | +[](https://github.com/your-username/react-native-api-logger/blob/main/LICENSE) |
| 7 | +[](https://reactnative.dev/) |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +<img |
| 12 | + src="/demo/demo_RN_logger.png" |
| 13 | + alt="Alt text" |
| 14 | + title="React Native API Logger" |
| 15 | + style="margin:0 4px; width: 200px" |
| 16 | +/> |
| 17 | + |
| 18 | + |
| 19 | +## Features |
| 20 | + |
| 21 | +- **Real-time Network Monitoring** - Automatically intercepts all fetch() and XMLHttpRequest calls |
| 22 | +- **Overlay Interface** - Non-intrusive floating button and modal interface |
| 23 | +- **Request Details** - View headers, body, response, timing, and status codes |
| 24 | +- **cURL Generation** - Copy requests as cURL commands for debugging |
| 25 | +- **Request Filtering** - Search and filter by URL, method, or API endpoints |
| 26 | +- **Error Tracking** - Easily identify failed requests and network errors |
| 27 | +- **Device Shake Support** - Optional shake-to-show functionality |
4 | 28 |
|
5 | 29 | ## Installation |
6 | 30 |
|
7 | | -```sh |
| 31 | +```bash |
8 | 32 | npm install react-native-api-debugger |
9 | 33 | ``` |
10 | 34 |
|
11 | | -## Usage |
| 35 | +### Peer Dependencies |
| 36 | + |
| 37 | +This package requires the following peer dependencies: |
| 38 | + |
| 39 | +```bash |
| 40 | +npm install @react-native-clipboard/clipboard react-native-shake react-native-svg |
| 41 | +``` |
| 42 | + |
| 43 | + |
| 44 | +## Quick Start |
| 45 | + |
| 46 | +### Basic Usage |
| 47 | + |
| 48 | +```typescript |
| 49 | +import React, { useEffect } from 'react'; |
| 50 | +import { View } from 'react-native'; |
| 51 | +import { networkLogger, NetworkLoggerOverlay } from 'react-native-api-debugger'; |
| 52 | + |
| 53 | +export default function App() { |
| 54 | + useEffect(() => { |
| 55 | + // Initialize the network logger |
| 56 | + networkLogger.setupInterceptor(); |
| 57 | + }, []); |
12 | 58 |
|
| 59 | + return ( |
| 60 | + <View style={{ flex: 1 }}> |
| 61 | + {/* Your app content */} |
| 62 | + |
| 63 | + {/* Add the network logger overlay */} |
| 64 | + <NetworkLoggerOverlay networkLogger={networkLogger} /> |
| 65 | + </View> |
| 66 | + ); |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +### With Device Shake Support |
| 71 | + |
| 72 | +```typescript |
| 73 | +import React, { useEffect } from 'react'; |
| 74 | +import { View } from 'react-native'; |
| 75 | +import { networkLogger, NetworkLoggerOverlay } from 'react-native-api-debugger'; |
| 76 | + |
| 77 | +export default function App() { |
| 78 | + useEffect(() => { |
| 79 | + networkLogger.setupInterceptor(); |
| 80 | + }, []); |
| 81 | + |
| 82 | + return ( |
| 83 | + <View style={{ flex: 1 }}> |
| 84 | + {/* Your app content */} |
| 85 | + |
| 86 | + {/* Enable shake-to-show functionality */} |
| 87 | + <NetworkLoggerOverlay |
| 88 | + networkLogger={networkLogger} |
| 89 | + enableDeviceShake={true} |
| 90 | + /> |
| 91 | + </View> |
| 92 | + ); |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | + |
| 97 | +### NetworkLoggerOverlay |
| 98 | + |
| 99 | +The UI component that displays the network logs. |
| 100 | + |
| 101 | +#### Props |
| 102 | + |
| 103 | +| Prop | Type | Default | Description | |
| 104 | +|------|------|---------|-------------| |
| 105 | +| `networkLogger` | `NetworkLogger` | **Required** | The network logger instance | |
| 106 | +| `enableDeviceShake` | `boolean` | `false` | Enable shake-to-show functionality | |
| 107 | + |
| 108 | +#### Example |
| 109 | + |
| 110 | +```typescript |
| 111 | +<NetworkLoggerOverlay |
| 112 | + networkLogger={networkLogger} |
| 113 | + enableDeviceShake={true} |
| 114 | +/> |
| 115 | +``` |
13 | 116 |
|
14 | | -```js |
15 | | -import { multiply } from 'react-native-api-debugger'; |
| 117 | +### Types |
16 | 118 |
|
17 | | -// ... |
| 119 | +The package exports TypeScript types for better development experience: |
18 | 120 |
|
19 | | -const result = await multiply(3, 7); |
| 121 | +```typescript |
| 122 | +import type { |
| 123 | + NetworkLog, |
| 124 | + NetworkResponse, |
| 125 | + NetworkRequestHeaders, |
| 126 | + LogListener |
| 127 | +} from 'react-native-api-debugger'; |
20 | 128 | ``` |
21 | 129 |
|
| 130 | +## Usage Examples |
| 131 | + |
| 132 | +### Development vs Production |
| 133 | + |
| 134 | +```typescript |
| 135 | +import { networkLogger, NetworkLoggerOverlay } from 'react-native-api-debugger'; |
| 136 | + |
| 137 | +export default function App() { |
| 138 | + useEffect(() => { |
| 139 | + // Only enable in development |
| 140 | + if (__DEV__) { |
| 141 | + networkLogger.setupInterceptor(); |
| 142 | + } |
| 143 | + }, []); |
| 144 | + |
| 145 | + return ( |
| 146 | + <View style={{ flex: 1 }}> |
| 147 | + {/* Your app content */} |
| 148 | + |
| 149 | + {/* Only show in development */} |
| 150 | + {__DEV__ && ( |
| 151 | + <NetworkLoggerOverlay |
| 152 | + networkLogger={networkLogger} |
| 153 | + enableDeviceShake={true} |
| 154 | + /> |
| 155 | + )} |
| 156 | + </View> |
| 157 | + ); |
| 158 | +} |
| 159 | +``` |
| 160 | + |
| 161 | +## Best Practices |
| 162 | + |
| 163 | +### 1. Development Only |
| 164 | + |
| 165 | +```typescript |
| 166 | +// Only enable in development builds |
| 167 | +if (__DEV__) { |
| 168 | + networkLogger.setupInterceptor(); |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +### 2. Memory Management |
| 173 | + |
| 174 | +The logger automatically limits stored requests to prevent memory issues: |
| 175 | +- Maximum 100 requests stored |
| 176 | +- Oldest requests are automatically removed |
| 177 | + |
| 178 | +### 3. Sensitive Data |
| 179 | + |
| 180 | +Be cautious with sensitive data in network requests: |
| 181 | +- The logger captures all headers and request/response bodies |
| 182 | +- Consider disabling in production builds |
| 183 | +- Review logged data before sharing screenshots |
| 184 | + |
| 185 | + |
| 186 | +### TypeScript Errors |
| 187 | + |
| 188 | +1. Ensure you're importing types correctly: |
| 189 | +```typescript |
| 190 | +import type { NetworkLog } from 'react-native-api-logger'; |
| 191 | +``` |
| 192 | + |
| 193 | +## Contributing |
| 194 | + |
| 195 | +We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details. |
| 196 | + |
| 197 | +## License |
| 198 | + |
| 199 | +MIT License - see [LICENSE](LICENSE) file for details. |
| 200 | + |
| 201 | +## Support |
| 202 | + |
| 203 | +- 🐛 **Bug Reports**: [GitHub Issues](https://github.com/your-username/react-native-api-logger/issues) |
| 204 | +- 💡 **Feature Requests**: [GitHub Discussions](https://github.com/your-username/react-native-api-logger/discussions) |
| 205 | +- 📖 **Documentation**: [Wiki](https://github.com/your-username/react-native-api-logger/wiki) |
| 206 | + |
| 207 | +--- |
| 208 | + |
| 209 | +**Made with ❤️ for React Native developers** |
22 | 210 |
|
23 | 211 | ## Contributing |
24 | 212 |
|
|
0 commit comments