thecodingdj/nettrace
iOS network debugging framework with real-time monitoring, JSON tree viewer, and request inspection.
Features
- Real-time network monitoring - automatically intercepts all
URLSessionrequests - Detailed request/response inspection - headers, body, status codes, timing
- Interactive JSON tree viewer with expand/collapse
- Search and filter by URL, method, or status code
- Copy JSON responses to clipboard
- Color-coded status indicators
- Non-intrusive floating button overlay
- HAR files export functionality to save the list and a single viewed request.
Installation
Swift Package Manager
In Xcode, go to File → Add Package Dependencies and enter:
https://github.com/theCodingDJ/NetTrace.gitOr add to your Package.swift:
dependencies: [
.package(url: "https://github.com/theCodingDJ/NetTrace.git", from: "1.1.0")
]Then add to your target:
.target(
name: "YourTarget",
dependencies: ["NetTrace"]
)Quick Start
Add the following into your AppDelegate:
import NetTrace
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if DEBUG
NetTrace.shared.start()
#endif
/// Other initialization code here.
return true
}HAR Export
NetTrace has the capability to export HAR files) to share with backend developers, or view with Charles Proxy/Postman/Proxyman.
[!TIP] When working with iPhone Simulator, to find your stored
.harfiles open your Terminal, runcd ~/Library/Developer/CoreSimulator/Devices/<Simulator UDID>(you can find your Simulator's UDID in Xcode → Window menu → Devices & Simulators), then run the following command in your Terminal:find . -name '*.har'.
Available Functions
NetTrace.shared.start()
Initializes NetTrace and displays the floating overlay button.
#if DEBUG
NetTrace.shared.start()
#endifNetTrace.shared.show()
Shows the overlay button if previously hidden.
NetTrace.shared.show()NetTrace.shared.hide()
Hides the overlay button.
NetTrace.shared.hide()NetRecorder.shared.clear()
Clears all logged requests.
NetRecorder.shared.clear()NetRecorder.shared.findRequests(where:)
Filters requests using complex logic.
let apiRequests = NetRecorder.shared.findRequests { request in
request.response?.statusCode == 404 && request.method == "POST"
}NetRecorder.shared.findRequests(byPath:)
Filters requests by URL path.
let apiRequests = NetRecorder.shared.findRequests(byPath: "/api")NetRecorder.shared.findRequests(byStatusCode:)
Filters requests by HTTP status code.
let errors = NetRecorder.shared.findRequests(byStatusCode: 404)NetRecorder.shared.findRequests(byMethod:)
Filters requests by HTTP method.
let postRequests = NetRecorder.shared.findRequests(byMethod: "POST")License
MIT License
Package Metadata
Repository: thecodingdj/nettrace
Default branch: main
README: README.md