GithubHelp home page GithubHelp logo

cppeter / responsedetective Goto Github PK

View Code? Open in Web Editor NEW

This project forked from netguru/responsedetective

0.0 1.0 0.0 387 KB

Sherlock Holmes of the networking layer. :male_detective:

License: MIT License

Swift 90.85% Ruby 2.14% Objective-C 7.01%

responsedetective's Introduction

ResponseDetective is a non-intrusive framework for intercepting any outgoing requests and incoming responses between your app and your server for debugging purposes.

Requirements

ResponseDetective is written in Swift 3.0.2 and supports iOS 8.0+, macOS 10.9+ and tvOS 9.0+.

Usage

Incorporating ResponseDetective in your project is very simple โ€“ it all comes down to just two steps:

Step 1: Enable interception

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.Manager(configuration: configuration)

And that's all!

Step 2: Profit

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"
 โ”‚ }

Installation

Carthage

If you're using Carthage, add the following dependency to your Cartfile:

github "netguru/ResponseDetective"

CocoaPods

If you're using CocoaPods, add the following dependency to your Podfile:

use_frameworks!
pod 'ResponseDetective'

About

This project is made with <3 by Netguru and maintained by Adrian Kashivskyy.

License

ResponseDetective is licensed under the MIT License. See LICENSE.md for more info.

responsedetective's People

Contributors

akashivskyy avatar serejahh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.