Skip to content

Repository files navigation

Local response

Local response is a powerful developer tool for iOS developers, allowing you to intercept and mock network traffic in your iOS apps without the need for certificates or proxy configurations. This tool is a lightweight alternative to Proxyman and Charles Proxy, specifically designed for simplicity and ease of use.

Features

  • Method Swizzling: Intercepts URLSession classes through method swizzling, capturing network requests and responses. No extra code changes required.
  • MacOS Companion App: Records all intercepted traffic in a dedicated macOS app, which listens for incoming data via a simple server.
  • Mock Responses: Easily override and mock network responses directly from the macOS app, enabling you to test various scenarios without modifying your code.
  • No Certificates or Proxy Needed: Unlike other tools, this solution does not require the installation of certificates or the use of a proxy, simplifying the setup process.

How to mock response

Installation

iOS Library

  1. Start the server

  2. Add the library to your project:

    • Using Swift Package Manager:

      dependencies: [
        .package(url: "https://github.com/chanonly123/local-response.git", from: "1.0.0")
      ]
    • Using Cocoapods: Add pod 'LocalResponse' to Podfile

    • Or by manually integrating the library into your project.

  3. Initialize the Interceptor:

In your AppDelegate or at the start of your app:

import LocalResponse

class AppDelegate: NSObject, UIApplicationDelegate {
   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
     #if DEBUG
         // for simulator
         LocalResponse.connect()
         // for simulator and other physical devices
         LocalResponse.connect(connectionUrl: "http://192.168.31.24:4040")
     #endif
   }
}

macOS App

Clone the repo and run the launch script — it builds the app and opens it for you:

git clone https://github.com/chanonly123/local-response.git
cd local-response
sh run.sh

That's it. run.sh builds Local Response Mapper with xcodebuild and launches the app.

  • Clean build: sh run.sh -clean
  • Xcode instead: open Local_Response_Mapper/Local Response Mapper.xcodeproj and run with Cmd+R.

Usage

  • Intercepting Traffic:

    • Once the library is initialized in your iOS app, all network requests made via URLSession will be intercepted and logged in the macOS app.
  • Mocking Responses:

    • In the macOS app, you can select any intercepted request and provide an overridden response. The iOS app will receive this mocked response as if it were from the actual server.

Examples

  • Logging Requests:

    • The macOS app provides a clear and detailed log of all intercepted network traffic, including URLs, headers, and body content.
  • Testing Error Scenarios:

    • Override network responses to simulate server errors, or custom data responses.

Screenshots

Records all http network calls, You can edit (Response, Headers, StatusCode)

alt tag

Contributing

Contributions are most welcome! Please open an issue or submit a pull request with your improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Inspired by the need for simpler traffic interception without the hassle of certificate management. Apart from that most of the solutions are paid.

Thanks To

A big thanks to the following open-source projects and contributors whose code has been used in this project:

atlantis - Capture HTTP/HTTPS, and Websocket from iOS app without proxy.

FlyingFox - Lightweight, HTTP server written in Swift using async/await.

Factory - A new approach to Container-Based Dependency Injection for Swift and SwiftUI.

realm-swift - Realm is a mobile database: a replacement for Core Data & SQLite.

Highlightr - iOS & OSX Syntax Highlighter.

CodeEditor - A SwiftUI TextEditor with syntax highlighting using Highlight.js

About

Mock iOS http API calls, without proxy and certificates, uses swizzling

Topics

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages