{"id":32317533,"url":"https://github.com/db-in/localserver","last_synced_at":"2026-02-26T04:01:59.436Z","repository":{"id":44470563,"uuid":"173251813","full_name":"db-in/LocalServer","owner":"db-in","description":"Simulate your Server APIs locally without Internet connectivity required","archived":false,"fork":false,"pushed_at":"2026-02-15T06:55:25.000Z","size":2520,"stargazers_count":10,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-02-15T10:07:49.515Z","etag":null,"topics":["alamofire","carthage","ios","localserver","macos","mock","network","osx","request","stub","stub-server","swift","swift-package-manager","tvos","uitest-server","urlsession","watchos","xcode"],"latest_commit_sha":null,"homepage":"https://db-in.github.io/LocalServer/","language":"HTML","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/db-in.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-03-01T07:02:22.000Z","updated_at":"2026-02-15T06:55:29.000Z","dependencies_parsed_at":"2026-02-15T05:04:11.081Z","dependency_job_id":null,"html_url":"https://github.com/db-in/LocalServer","commit_stats":{"total_commits":53,"total_committers":2,"mean_commits":26.5,"dds":0.1132075471698113,"last_synced_commit":"3653e40528fc45e93811cae91a437fd3e4ca1704"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/db-in/LocalServer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-in%2FLocalServer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-in%2FLocalServer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-in%2FLocalServer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-in%2FLocalServer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/db-in","download_url":"https://codeload.github.com/db-in/LocalServer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/db-in%2FLocalServer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29848660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T22:37:40.667Z","status":"online","status_checked_at":"2026-02-26T02:00:06.774Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["alamofire","carthage","ios","localserver","macos","mock","network","osx","request","stub","stub-server","swift","swift-package-manager","tvos","uitest-server","urlsession","watchos","xcode"],"created_at":"2025-10-23T11:11:46.495Z","updated_at":"2026-02-26T04:01:59.431Z","avatar_url":"https://github.com/db-in.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LocalServer\n\n[![Build Status](https://travis-ci.org/db-in/LocalServer.svg?branch=master)](https://travis-ci.org/db-in/LocalServer)\n[![codecov](https://codecov.io/gh/db-in/LocalServer/branch/master/graph/badge.svg)](https://codecov.io/gh/db-in/LocalServer)\n[![codebeat badge](https://codebeat.co/badges/5563135f-7e49-4e66-aa44-b4f6fbb9b331)](https://codebeat.co/projects/github-com-db-in-localserver-master)\n![Version](https://img.shields.io/badge/swift-5.0-red.svg)\n[![Platform](https://img.shields.io/cocoapods/p/LocalServer.svg?style=flat)](https://db-in.github.io/LocalServer)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/LocalServer.svg)](https://img.shields.io/cocoapods/v/LocalServer.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n## Description\n**LocalServer** is a framework that provides various options to create a Swift Stub Local Server right into the code, that can independently run on simulators and devices, supporting Xcode Parallel Testing. It's made in Swift to create Stub Servers, UITest Servers and providing an easy way to Mock capabilities to create Testing doubles (fakes, stubs, spies and mocks). It supports all Apple platform iOS, MacOS, WatchOS and TVOS.\n\nIt's also fully compatible with most the Networking libraries like Alamofire, Moya, AFNetworking or the native URLSession and NSURLConnection. Check the **Programming Guide** section for examples.\n\n**Features**\n\n- [x] Create Stub servers without changing or injecting any of your existing URLSession code\n- [x] Create Stub versions for WKWebView\n- [x] Supports Xcode Parallel Testing in simulators and devices\n- [x] Stub Server for Unit Testing\n- [x] UITest Stub Server for UI Testing\n\n|Running App|UITest with Local Server|\n|:---------:|:----------------------:|\n|Random Users are generated|Only the mocked users are generated|\n|![Sample App](./Resources/Sample.gif)|![Sample App](./Resources/SampleUITest.gif)|\n\n\n## Installation\n\nYou can use LocalServer straight into your Unit Testing target, without any extra code to your main target. Once the Unit Test runs within the main target.\n\nOnly for UI Testing targets, it's required some extra code in the main target.\n\n### Using [CocoaPods](https://cocoapods.org)\n\nAdd to your **Podfile** file\n\n```\npod 'LocalServer'\n```\n\n### Using [Carthage](https://github.com/Carthage/Carthage)\n\nAdd to your **Cartfile** or **Cartfile.private** file\n\n```\ngithub \"db-in/LocalServer\"\n```\n\n### Using [Swift Package Manager](https://swift.org/package-manager)\n\nAdd to your **Package.swift** file\n\n```swift\nlet package = Package(\n    name: \"myproject\",\n    dependencies: [\n        .package(url: \"https://github.com/db-in/LocalServer\"),\n    ],\n    targets: [\n        .target(\n            name: \"myproject\",\n            dependencies: [\"LocalServer\"]),\n    ]\n)\n```\n\n## Programming Guide\nThe features provided are:\n\n- Third party Networking Libraries\n- Stub Server\n- UITest Server\n\n#### Third party Networking Libraries (Alamofire, Moya, and others)\n\nMocking your **Unit Test Target** without modifying a single line of code in yourmain target! You don't need to polute your production code with testing libraries or create any architecture specifically for allowing testability.\n\nKeep your production networking code the way you prefer and just to your **Unit Test Target** you add:\n\n```swift\nimport LocalServer\n\n...\n\nStubResponse(json: [\"param\" : \"value\"])\n    .withStatusCode(200)\n    .send(to: \"apple\")\n```\n\nThis code above is enough to mock any calls matching anything containing `\"apple\"` in the URL and returning 200 HTTP status code with the JSON mock defined above.\n\n#### Stub Server\nThe Stub Server is the base for the Local Server. It can intercept any network call made with the URLSession.\n\n![Stub Server](./Resources/StubServer.png)\n\nThese are some of the handful functions for creating `StubResponse`:\n\n```swift\nStubResponse(string: \"UTF8 string to become body\")\nStubResponse(json: [\"param\" : \"value\", \"number\": 1])\nStubResponse(filename: \"file\", ofType: \"html\")\nStubResponse(filename: \"file\", ofType: \"json\", bundle: myBundle)\nStubResponse(data: myBodyData)\n```\n\nFor a more granular and specific approach, defining a different response for each HTTP:\n\n```swift\nimport LocalServer\n\n...\n\nfunc startMyLocalServer() {\n    let server = StubServer()\n\t\t\n\tserver.route([.GET], url: \"https://apple.com\") { (request, parameters) -\u003e StubResponse in\n\t\treturn StubResponse().withStatusCode(204)\n\t}\n\t\n\tserver.route([.POST], url: \"https://apple.com\") { _,_ in\n\t\treturn StubResponse().withStatusCode(206)\n\t}\n\t\t\n\tStubServer.instance = server\n}\n```\n\nYou can also test Network errors:\n\n```swift\nStubResponse()\n    .withError(MyMockNetworkError.noInternet)\n    .send(to: \"https://apple.com\")\n```\n\nIMPORTANT: When defining the mock URL for the same HTTP method, remember that the URL uses **regex** to evaluate, which means regexes may override each other mistakenly and cause wrong behaviors.\nAlso the `send(to:)` is a convenient method and thus uses a shared server under the hood. It's reset everytime you set the `StubServer.instance` to `nil`. \n\nOnce the `StubServer.instance` is defined as non-nil, it will spin the Local Server. To stop the Local Server just set it back to `nil`, which is the default value.\n\n#### UITest Server\nAs per Apple design, the UITest target runs on a separated application, which means it can't have access to the code in the main application or perform any programaticaly action. The UITest Server used the `ProcessInfo` bridge to send data from the UITest target to the main application on every launch.\n\nAs per Testing best practices, every UITest case should restart the main Application.\n\n![UITest Server](./Resources/UITestServer.png)\n\nProject Structure\n\n```swift\n// UITest Target\n |-- LocalServer\n |-- JsonFile1.json\n |-- JsonFile2.json\n |-- JsonFile2.json\n \n// Main Target\n |-- LocalServer\n```\n\nRequired Code\n\n```swift\n// UITest Target\nUITestResponse()\n    .withStatusCode(201)\n    .send(to: \"google.com\")\n\n// Main Target\nUITestServer.start() \n```\n\n## FAQ\n\u003e Can I ship LocalServer to production (App Store)?\n\n- Yes, absolutely. The main goal is to provide Mock and Stub capabilities, but nothing stops you to use it in production if required.\n\n\u003e If I'm only using it for Debug purpose, shall I use `#if DEBUG`?\n\n- As a dynamic Swift framework, LocalServer will only be loaded in runtime at the moment it's first called. So if your production code never makes use of any LocalServer API, it will not even be loaded. `#if DEBUG` can be used, but as per UITest Standards, you can also consider the usage of something like `XCUIApplication().launchArguments` + `if ProcessInfo().arguments.contains(\"-UITests\") { ... }`\n- [UI Testing Quick Guide/](https://useyourloaf.com/blog/ui-testing-quick-guide)\n- [Getting Started With Xcode UI Testing In Swift](https://www.swiftbysundell.com/posts/getting-started-with-xcode-ui-testing-in-swift)\n\n\u003e Can I simulate a slow network response?\n\n- Yes, you can use the `delay` property in any response object to simulate that.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdb-in%2Flocalserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdb-in%2Flocalserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdb-in%2Flocalserver/lists"}