ResponseDetective is a non-intrusive framework for intercepting any outgoing requests and incoming responses between your app and your server for debugging purposes.
ResponseDetective is written in Swift 5.3 and supports iOS 9.0+, macOS 10.10+ and tvOS 9.0+.
Incorporating ResponseDetective in your project is very simple β it all comes down to just two steps:
For ResponseDetective to work, it needs to be added as a middleman between your (NS)URLSession and the Internet. You can do this by registering the provided URLProtocol class in your session's (NS)URLSessionConfiguration.protocolClasses, or use a shortcut method:
// Objective-C
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
[RDTResponseDetective enableInConfiguration:configuration];// Swift
let configuration = URLSessionConfiguration.default
ResponseDetective.enable(inConfiguration: configuration)Then, you should use that configuration with your (NS)URLSession:
// Objective-C
NSURLSession *session = [[NSURLSession alloc] initWithConfiguration:configuration];// Swift
let session = URLSession(configuration: configuration)Or, if you're using AFNetworking/Alamofire as your networking framework, integrating ResponseDetective comes down to just initializing your AFURLSessionManager/Manager with the above (NS)URLSessionConfiguration:
// Objective-C (AFNetworking)
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];// Swift (Alamofire)
let manager = Alamofire.SessionManager(configuration: configuration)And that's all!
Now it's time to perform the actual request:
// Objective-C
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://httpbin.org/get"]];
[[session dataTaskWithRequest:request] resume];// Swift
let request = URLRequest(URL: URL(string: "http://httpbin.org/get")!)
session.dataTask(with: request).resume()VoilΓ ! π Check out your console output:
<0x000000000badf00d> [REQUEST] GET https://httpbin.org/get
ββ Headers
ββ Body
β <none>
<0x000000000badf00d> [RESPONSE] 200 (NO ERROR) https://httpbin.org/get
ββ Headers
β Server: nginx
β Date: Thu, 01 Jan 1970 00:00:00 GMT
β Content-Type: application/json
ββ Body
β {
β "args" : {
β },
β "headers" : {
β "User-Agent" : "ResponseDetective\/1 CFNetwork\/758.3.15 Darwin\/15.4.0",
β "Accept-Encoding" : "gzip, deflate",
β "Host" : "httpbin.org",
β "Accept-Language" : "en-us",
β "Accept" : "*\/*"
β },
β "url" : "https:\/\/httpbin.org\/get"
β }
If you're using Carthage, add the following dependency to your Cartfile:
github "netguru/ResponseDetective" ~> {version}
If you're using CocoaPods, add the following dependency to your Podfile:
use_frameworks!
pod 'ResponseDetective', '~> {version}'
If you're using Swift Package Manager, add this repository to the Swift Packages in your project settings.
To install the test dependencies or to build ResponseDetective itself, do not run carthage directly. It can't handle the Apple Silicon architectures introduced in Xcode 12. Instead, run it through the carthage.sh script:
$ ./carthage.sh bootstrapAlternatively, you can run the tests locally using Swift Package Manager with the following command:
$ swift testThis project was made with β‘ by Netguru.
Starting from version 1.0.0, ResponseDetective's releases are named after Sherlock Holmes canon stories, in chronological order. What happens if we reach 60 releases and there are no more stories? We don't know, maybe we'll start naming them after cats or something.
This project is licensed under MIT License. See LICENSE.md for more info.