A Swift framework 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.
-
Real-time network monitoring
- Capture URL, method, status code, response time, headers, request body, and response body
- Live updates with in-progress indicators for pending requests
- Start immediately or use on-demand mode to enable monitoring from the UI when needed
- Color-coded list view with method badges, status indicators, and response metrics
-
Filtering and search
- Filter by status code ranges and HTTP methods
- Combine multiple filters with visual filter chips
- Full-text URL search across all captured requests
-
Detailed request inspection
- Tabbed detail view: Overview, Request, Headers, and Response
- Smart response rendering — pretty-printed JSON, inline image previews, and plain text
- Copy any request or response data to clipboard
- Create a mock or skip rule directly from a captured request
-
Export in multiple formats
- CSV — bulk or single request export for spreadsheets and analysis
- Plain text — human-readable format for quick sharing
- Postman Collection — import directly into Postman for API testing
-
Mock responses
- Intercept requests and return custom responses without a backend
- Flexible matching: hostname, URL, path, endPath, subPath
- Configure status codes, headers, JSON/raw body, and response delay
- Programmatic mocking — register mocks via code for unit tests and development
- UI-based mocking — let QA testers create and manage mocks on the fly without Xcode
- Persist mocks across app sessions with local storage
-
Skip request logging
- Exclude noisy or sensitive requests using the same flexible matching rules
- Configure skip rules programmatically or from the UI
- Persist rules across app launches
-
Insights dashboard
- Summary cards: total requests, success rate, and unique hosts
- Interactive charts for status code distribution, HTTP methods, host traffic, and request timeline
-
Log history
- Automatically save session logs to disk for later review
- Browse past sessions from Tools
- Enable or disable history persistence from settings
-
Lightweight and easy to integrate
- One-line setup to start monitoring
- No XIB/Storyboards, no external dependencies
- Works with SwiftUI, UIKit, and AppKit
- Toggle debug console logging on or off
- Supports both light and dark mode
-
Cross-platform
- 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)
// Remove all registered mocks
NetworkSpectator.stopMocking()
// Skip logging for specific requests
NetworkSpectator.ignoreLogging(for rule: MatchRule)
// Remove all skip logging rules
NetworkSpectator.stopIgnoringLog()Start NetworkSpectator in on-demand mode to let users enable monitoring from the UI:
NetworkSpectator.start(onDemand: true)If enabled, then, to stop network monitoring:
NetworkSpectator.stop()The following screenshots demonstrate NetworkSpectator running on iOS.
| List of Requests | Filters | URL Search | Details |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Headers | Response | Tools | History |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Insights | Insights - Timeline | Insights - Status code | Insights - Performance |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
The following screenshots demonstrate NetworkSpectator running on macOS.
| List of Requests | Filters | Details |
|---|---|---|
![]() |
![]() |
![]() |
| Headers | Response | Tools |
|---|---|---|
![]() |
![]() |
![]() |
| Insights | Timeline | Performance |
|---|---|---|
![]() |
![]() |
![]() |
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.




















