{"id":22549602,"url":"https://github.com/enhorn/onenetwork","last_synced_at":"2026-02-05T06:03:07.348Z","repository":{"id":54782676,"uuid":"213978242","full_name":"enhorn/OneNetwork","owner":"enhorn","description":"One minimalistic networking library for SwiftUI.","archived":false,"fork":false,"pushed_at":"2024-11-07T13:14:46.000Z","size":127,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T01:59:42.755Z","etag":null,"topics":["google","google-api","ios","network","oauth","spotify","spotify-api","swift","swift-package-manager","swiftui","swiftui-framework"],"latest_commit_sha":null,"homepage":"","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/enhorn.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}},"created_at":"2019-10-09T17:14:06.000Z","updated_at":"2024-11-07T13:14:49.000Z","dependencies_parsed_at":"2025-04-10T01:53:15.671Z","dependency_job_id":"15c7d285-9228-4d90-a2f4-939979049acf","html_url":"https://github.com/enhorn/OneNetwork","commit_stats":null,"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"purl":"pkg:github/enhorn/OneNetwork","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enhorn%2FOneNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enhorn%2FOneNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enhorn%2FOneNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enhorn%2FOneNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enhorn","download_url":"https://codeload.github.com/enhorn/OneNetwork/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enhorn%2FOneNetwork/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29114500,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T05:31:32.482Z","status":"ssl_error","status_checked_at":"2026-02-05T05:31:29.075Z","response_time":65,"last_error":"SSL_read: 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":["google","google-api","ios","network","oauth","spotify","spotify-api","swift","swift-package-manager","swiftui","swiftui-framework"],"created_at":"2024-12-07T16:09:20.872Z","updated_at":"2026-02-05T06:03:07.341Z","avatar_url":"https://github.com/enhorn.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OneNetwork\n\nMinimalistic networking library with SwiftUI in mind.\n\n- Build simple UI components with 1:1 network connection to views.\n- Automatically parse to your `Codable` models from the response JSON.\n- Predestine your network responses during development, making your `PreviewProvider` implementations network independent. No need to muck about with complex mocking solutions for unit \u0026 UI tests either.\n- OAUth authentication, with predefined authentications for Google \u0026 Spotify, both available as login examples in the bundled Example app (needs Client ID etc.).\n- Support for Async / Await.\n- Example app with implementations of network requests and and different authentication options.\n\n## Example usage\nIn a view we'd like to list some articles, we have already created our model that fulfills `Codable` \u0026 `Identifiable`, so we head straight on the network,\n\n### The Network Implementation\n```swift\nclass ArticlesNetwork: OneNetwork {\n\n    @Published private(set) var articles: [Article] = [] {\n        willSet { objectWillChange.send() }\n    }\n\n    func updateArticleList() {\n        let url = URL(string: \"your endpoint url\")\n        let request = URLRequest(url: url) // Apply any custom authentication if needed.\n        get(request: request) { [weak self] (result: [Article]?) in\n            self?.articles = result ?? []\n        }\n    }\n\n}\n```\n\n### Inside the View\n\n```swift\nstruct ContentView: View {\n\n    @ObservedObject var network: ArticlesNetwork\n\n    var body: some View {\n        List(network.articles) { article in\n            Text(article.title)\n        }.onAppear(perform: self.network.updateArticleList)\n    }\n\n}\n\nstruct ContentView_Previews: PreviewProvider {\n    static var previews: some View {\n        // By supplying a predestined cache here,\n        // the view will be able to behave like it is networking like normal.\n        ContentView(network: ArticlesNetwork(cache: .predestinedArticlesCache))\n    }\n}\n```\n\n## Async / Await\n\nOneNetwork also support Async / Await, which can be used outside of SwiftUI.\nHere we see how the type is inferred from the result type of the fetch function.\n\n```swift\nclass AsyncNetwork: OneNetwork {\n\n    func fetchItems() async -\u003e [Item]? {\n        await get(\n            request: URLRequest(\n                url: URL(string: \"your endpoint url\")\n            )\n        )\n    }\n\n}\n```\n\n## OAuth\n\nThere is a standardized interface to perform OAuth authentication on iOS, where custom implementations can be supplied.\nBoth Google and Spotify authentications for iOS is available prebuilt.\n\n### Code example with Google OAuth\n\n```swift\nclass AuthenticationNetwork: OneNetwork {\n\n    func login(onDone: @escaping (_ success: Bool) -\u003e Void) {\n        authenticate(\n            with: OneGoogleOAuthLogin(\n                clientID: \"Your Google API app client ID\",\n                urlScheme: \"Your Google API app URL scheme\",\n                scopes: [\"API scope accesses that will be requested.\"]\n            ),\n            onLoggedIn: { [weak self] session in\n                /// Save the `session` for future use.\n                onDone(true)\n            },\n            onFail: { error in\n                onDone(false)\n            }\n        )\n    }\n\n}\n```\n\n### Code example with Spotify OAuth\n\n```swift\nclass AuthenticationNetwork: OneNetwork {\n\n    func login(onDone: @escaping (_ success: Bool) -\u003e Void) {\n        authenticate(\n                with: OneSpotifyOAuthLogin(\n                clientID: \"Your client ID\",\n                clientSecret: \"Your client secret\",\n                redirectURI: \"Your redirect URI\",\n                scopes: [\"API scope accesses that will be requested.\"]\n            ),\n            onLoggedIn: { [weak self] session in\n                /// Save the `session` for future use.\n                onDone(true)\n            },\n            onFail: { error in\n                onDone(false)\n            }\n        )\n    }\n\n}\n```\n\n## Example app\nThe example iOS app is built with SwiftUI and is using predestined requests for network free previews, both basic and OAuth authentication, as well as pagination.\nYou will need to supply clientID \u0026 urlScheme from your API app, as well what API scopes it supports.\nUses the public example API from: https://reqres.in made by [@benhowdle89](https://github.com/benhowdle89)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenhorn%2Fonenetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenhorn%2Fonenetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenhorn%2Fonenetwork/lists"}