{"id":24350759,"url":"https://github.com/imodeveloperlab/relay","last_synced_at":"2026-02-02T15:39:27.891Z","repository":{"id":266671642,"uuid":"898982973","full_name":"imodeveloperlab/Relay","owner":"imodeveloperlab","description":"Relay is a Swift framework that simplifies recording, replaying, intercepting, and modifying network requests to enhance testing and debugging of network interactions in iOS applications.","archived":false,"fork":false,"pushed_at":"2024-12-06T15:17:44.000Z","size":79,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T07:26:22.937Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imodeveloperlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-05T12:03:09.000Z","updated_at":"2024-12-09T07:20:49.000Z","dependencies_parsed_at":"2024-12-05T13:35:16.100Z","dependency_job_id":"a3c7e54c-3537-4253-b176-fb2471be22bb","html_url":"https://github.com/imodeveloperlab/Relay","commit_stats":null,"previous_names":["imodeveloperlab/relay"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/imodeveloperlab/Relay","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imodeveloperlab%2FRelay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imodeveloperlab%2FRelay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imodeveloperlab%2FRelay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imodeveloperlab%2FRelay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imodeveloperlab","download_url":"https://codeload.github.com/imodeveloperlab/Relay/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imodeveloperlab%2FRelay/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29014495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T14:58:54.169Z","status":"ssl_error","status_checked_at":"2026-02-02T14:58:51.285Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-18T14:04:48.814Z","updated_at":"2026-02-02T15:39:27.875Z","avatar_url":"https://github.com/imodeveloperlab.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎛️ Relay\n\nRelay is a Swift framework that simplifies recording, replaying, intercepting, and modifying network requests to enhance testing and debugging of network interactions in iOS applications.\n\n## Purpose\n\nThe primary use case for Relay is **unit tests and SwiftUI previews that require server connections**. By recording server responses once and replaying them in subsequent runs, you ensure fast, consistent, and reliable tests without constantly hitting the actual server. Relay also shines in **SwiftUI previews**, allowing you to load previews using previously recorded data. This accelerates the preview process, lets you manipulate a single recorded response for various states, and avoids repeatedly calling the server.\n\n## How It Works\n\nWhen you run your test or preview with `isRecordingEnabled = true`, Relay intercepts HTTP requests and captures both the request and the corresponding response. These are stored as separate files in a structured directory (e.g., `__RelayRecords__`) relative to the test or preview code file. On subsequent runs, when `isRecordingEnabled = false`, Relay looks up these stored files and returns their recorded responses without making actual network calls. This means you can rely on consistent and stable test inputs and fast-loading previews.\n\nBelow is an example of how recorded files might be organized:\n\n```\nTests\n └─ __RelayRecords__\n     ├─ customSession\n     │   └─ GET-typicode.com-posts_a25b94c312bb64a5\n     ├─ defaultSession\n     │   └─ GET-typicode.com-posts_e3fdab5b4d16442f\n     ├─ handleMultipleRequests\n     │   ├─ GET-typicode.com-posts_9986e99294a801c6\n     │   ├─ GET-typicode.com-users_1a8fe3094918fe243\n     │   └─ POST-typicode.com-posts_ea6ce919bf1be8a6\n     ... and so on\n```\n\nEach directory represents a specific test scenario or function call, and each file inside corresponds to a particular network request/response pair that Relay recorded.\n\n## Features\n\n- **Record and Replay**: Capture network requests and responses once, and replay them for tests and previews to ensure consistent, reproducible results.\n- **Flexible Response Modification**: Dynamically override JSON key-value pairs to simulate different states or conditions using the same recording.\n- **Request Interception**: Intercept and optionally modify requests based on URL keywords for enhanced testing and preview scenarios without constant server calls.\n\n## Workflow\n\n1. **Initial Setup and Recording**:  \n   - Run your unit test or SwiftUI preview with `isRecordingEnabled = true`.  \n   - Relay records all intercepted network requests and their responses.\n\n2. **Subsequent Uses with Recorded Data**:  \n   - Turn off recording (`isRecordingEnabled = false`).  \n   - Relay now uses the previously recorded responses from the file system, ensuring no live server calls.\n\n3. **Manipulating Recorded Results**:  \n   - Use `jsonValueOverrides` to modify parts of the recorded response dynamically, simulating different states without needing new recordings.\n\n## Usage\n\nFirst, import Relay at the top of your Swift file:\n\n```swift\nimport Relay\n```\n\n### Recording and Replaying Requests\n\n```swift\nlet processor = Relay.recordAndReplay(\n    isRecordingEnabled: true, // Set to true for your first run to record\n    urlKeywords: [\"api.example.com\"],\n    jsonValueOverrides: [\"token\": \"REDACTED\"]\n)\n```\n\n**Parameters:**\n\n- **`isRecordingEnabled`**:  \n  - `true`: Capture and store responses during the initial run.  \n  - `false`: Subsequent runs use recorded data, ensuring no live server calls.\n- **`urlKeywords`**: Filter requests by URL keywords.\n- **`jsonValueOverrides`**: A dictionary of keys and their override values to manipulate responses.\n\n**Recording Folder Structure:**\n\n- **`recordingRootFolder`**: Automatically detected based on the file invoking `recordAndReplay`, with all recordings stored under a `__RelayRecords__` folder.\n- **`recordingFolder`**: Defaults to the function name from which `recordAndReplay` was called, making it easy to identify which tests generated which recordings.\n\n**Important Note on Test Environments:**\n\n\u003e ⚠️ **Warning:** When replaying network requests with Relay in unit tests, **disable test parallelization**. Relay supports only one replay session at a time. Configure your test suite to run serially by setting the test scheme's `Execution Order` to **Sequential** in Xcode.\n\n### Intercepting Requests \u0026 Modifying Responses\n\nTo intercept network requests and modify responses without recording:\n\n```swift\nRelay.interceptAndModify(\n    urlKeywords: [\"api.example.com\"],\n    jsonValueOverrides: [\"token\": \"REDACTED\"]\n)\n```\n\n### Using Custom `URLSession` Configurations\n\nIf you're using a custom `URLSession` with a custom `URLSessionConfiguration`, you have two options to ensure that Relay can intercept the requests:\n\n1. **Initialize Relay Before Session Creation**:  \n   Call `recordAndReplay` or `interceptAndModify` **before** creating your custom `URLSession`.\n\n2. **Manually Set `protocolClasses`**:  \n   If the session is already created, manually set `protocolClasses` to include `RelayURLProtocol`:\n\n   ```swift\n   static let urlSession: URLSession = {\n       let config = URLSessionConfiguration.default\n       config.httpAdditionalHeaders = [\"x-key\": \"key\", \"x-platform\": \"ios\"]\n       config.protocolClasses = [RelayURLProtocol.self]\n       return URLSession(configuration: config)\n   }()\n   ```\n\n## Installation\n\n### Swift Package Manager\n\nRelay supports installation via **Swift Package Manager**.\n\n1. In Xcode, select **File \u003e Add Packages**.\n2. Enter the repository URL:\n   ```\n   https://github.com/imodeveloperlab/Relay.git\n   ```\n3. Choose the version you want to install.\n4. Add the package to your project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimodeveloperlab%2Frelay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimodeveloperlab%2Frelay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimodeveloperlab%2Frelay/lists"}