{"id":21619071,"url":"https://github.com/bannzai/xchanger","last_synced_at":"2025-06-30T12:37:29.004Z","repository":{"id":52646583,"uuid":"276694677","full_name":"bannzai/XChanger","owner":"bannzai","description":"XChanger can exchange to behavior for URL request and response","archived":false,"fork":false,"pushed_at":"2021-04-22T13:17:17.000Z","size":69,"stargazers_count":35,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-26T20:18:04.840Z","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/bannzai.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}},"created_at":"2020-07-02T16:24:25.000Z","updated_at":"2022-05-08T06:31:53.000Z","dependencies_parsed_at":"2022-08-21T12:10:19.077Z","dependency_job_id":null,"html_url":"https://github.com/bannzai/XChanger","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/bannzai/XChanger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FXChanger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FXChanger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FXChanger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FXChanger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bannzai","download_url":"https://codeload.github.com/bannzai/XChanger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FXChanger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262774939,"owners_count":23362412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2024-11-24T23:07:49.587Z","updated_at":"2025-06-30T12:37:28.980Z","avatar_url":"https://github.com/bannzai.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XChanger\nXChange makes us enable to do mocking response with URL easily.\n\n## Usage\nBefore start to register mocks, you need to call just one sentence, `XChanger.register()`, in some starting points like `@main`, `AppDelegate`, `SceneDelegate` or head of method in your unit test cases.\n```swift\nXChanger.register()\n```\n\nThen, passing response mock data with URL request as a key.\nHere is the example for the URL `https://exmaple.com/v1/users/10`, and will return the 200 response with the body `{\"id\": 10, name:\"bannzai\"}`. \n\n```swift\nstruct User: Codable {\n  var id: Int\n  var name: String\n}\n\nlet url = \"https://exmaple.com/v1/users/10\"\nlet json = try! JSONEncoder().encode(User(id: 10, name: \"bannzai\"))\nXChanger.exchange().request(url: url).response(data: json, statusCode: 200).enable()\n```\n\nFinally, you can send URLRequest normaly, and you can see the response is what you defined.\n\n```swift\nlet request = URLRequest(url: URL(string: \"https://exmaple.com/v1/users/10\")!)\nlet session = URLSession(configuration: URLSessionConfiguration.default)\nsession.dataTask(with: request) { data, response, error in\n  guard let httpResponse = response as? HTTPURLResponse else {\n      return fatalError(\"Unexpected response type of HTTPURLResponse\")\n  }\n  print(httpResponse.statusCode) // 200\n  \n  let decoded = try! JSONDecoder().decode(User.self, from: data!)\n  print(decoded) // User(id: 10, name: \"bannzai\")\n}.resume()\n```\n\n## Installing\n### Cocoapods\n\n```ruby\npod 'XChanger', configuration: %w(Debug)\n```\n\n### Swift Package Manager\n#### Xcode\nOpen File \u003e Swift Packages \u003e Add Package Dependency... and put Repository URL https://github.com/bannzai/XChanger.\nThis [document](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app) will also help you.\n\n#### Use as dependency\n\nAdd the following to your Package.swift file's dependencies:\n\n```\n.package(url: \"https://github.com/bannzai/XChanger.git\", from: \"0.0.1\")\n```\n\n## LICENSE\nXChanger is released under the MIT license. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbannzai%2Fxchanger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbannzai%2Fxchanger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbannzai%2Fxchanger/lists"}