A lightweight Swift utility for monitoring and inspecting your app's HTTP traffic during development and testing. NetworkSpectator captures requests and responses, provides a clean UI for browsing and mocking them, and allows you to export logs for sharing.
-
Monitor network requests and responses in real time
- URL, method, status code, response time, request/response headers, request body and response body
- Simple list and detail views for quick inspection
- Analytics dashboard with charts for HTTP methods, status codes, and host distribution
-
Filters and Search
- Filter requests by status codes and HTTP methods
- Find specific requests by URL using search
-
Export logs in multiple formats
NetworkSpectator supports multiple export formats:
- CSV - For importing into spreadsheet applications or data analysis tools
- Plain text - Simple format for quick sharing or viewing in text editors
- Postman Collection format - Import directly into Postman for API testing and collaboration
-
Mock responses
- Define custom mock responses using rule-based matching
- Test different scenarios and edge cases without backend API deployment
- Programmatic mocking - Add mocks via code without complex stubbing setups
- UI-based mocking - Enable QA testers to validate business logic in test builds independently, without developer intervention or running app with Xcode
- Helps to speed up development using mock response
- Edit and update mock rules on the fly from UI
-
Skip a request from logging
- Exclude specific or sensitive requests from logging using matching rules
- Reduce noise by filtering out irrelevant requests
- Configure skip rules both programmatically (in code) and dynamically (via UI)
- Edit and update skip rules from UI
-
Lightweight and easy to integrate
- One line setup to start monitoring and logging
- No external dependencies
- Works with SwiftUI and UIKit/AppKit
- Manage log prints on Xcode debug console
-
Cross-platform support
- iOS 16.0+
- macOS 13.0+
Add NetworkSpectator to your project using Swift Package Manager:
- In Xcode, select File > Add Package Dependencies...
- Enter the package repository URL - https://github.com/Pankajbawane/NetworkSpectator.git
Or add it to your Package.swift:
dependencies: [
.package(url: "https://github.com/pankajbawane/NetworkSpectator.git", branch: "main")
]The NetworkSpectatorExample app demonstrates basic usage of the library: https://github.com/Pankajbawane/NetworkSpectatorExample
- Enable NetworkSpectator in your app's entry point (AppDelegate or App struct):
Call NetworkSpectator.start() to begin listening to HTTP requests. This will automatically log all HTTP traffic.
import NetworkSpectator
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.task {
#if DEBUG
NetworkSpectator.start()
#endif
}
}
}
}- Present the NetworkSpectator UI:
import NetworkSpectator
ContentView() {
}
.sheet(isPresented: $showLogs) {
NetworkSpectator.rootView
}import NetworkSpectator
let networkVC = NetworkSpectator.rootViewController
present(networkVC, animated: true)import NetworkSpectator
let networkVC = NetworkSpectator.rootViewController
presentAsSheet(networkVC)Customize NetworkSpectator behavior with the configuration methods:
// Enable or disable printing logs to the debug console
NetworkSpectator.debugLogsPrint(isEnabled: Bool)
// Register a mock response
NetworkSpectator.registerMock(for mock: Mock)
// Skip logging for specific requests
NetworkSpectator.ignoreLogging(for rule: MatchRule)If enabled, then, to stop network monitoring:
NetworkSpectator.stop()The following screenshots demonstrate NetworkSpectator running on iOS in light mode.
| List of Requests | Filters | URL Search | Details |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Headers | Response | Settings | Export & Share |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
The following screenshots demonstrate NetworkSpectator running on macOS in dark mode.
| List of Requests | Filters | Details |
|---|---|---|
![]() |
![]() |
![]() |
| Headers | Response | Analytics |
|---|---|---|
![]() |
![]() |
![]() |
| Settings | Add Mock | Skip Logging |
|---|---|---|
![]() |
![]() |
![]() |
Because NetworkSpectator captures and displays network information, you should limit it to debug/test builds only. Wrap your integration points with #if DEBUG to ensure nothing leaks into release builds.
- Always guard with
#if DEBUGand/or internal feature flags - Ensure NetworkSpectator is not initialized in release configurations
// Monitoring will start only for a debug build.
#if DEBUG
NetworkSpectator.start()
#endif- Swift 6+
- iOS 16.0+ / macOS 13.0+
- Xcode 16.0+
MIT license. View LICENSE for more details.
















