{"id":25082245,"url":"https://github.com/niksativa/smartnetwork","last_synced_at":"2025-10-16T18:23:39.340Z","repository":{"id":38236103,"uuid":"290461244","full_name":"NikSativa/SmartNetwork","owner":"NikSativa","description":"Light weight wrapper around URLSession","archived":false,"fork":false,"pushed_at":"2025-03-27T13:57:44.000Z","size":1222,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T08:16:16.305Z","etag":null,"topics":["api","async-await","auth","curl","fast","interception","interceptor","ios","json","mac","macos","plugin","request","rest","stoptheline","strongly-typed","swift","urlsession","visionos","watchos"],"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/NikSativa.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":"2020-08-26T10:03:57.000Z","updated_at":"2025-03-27T13:57:38.000Z","dependencies_parsed_at":"2023-01-31T09:31:51.519Z","dependency_job_id":"45767052-7924-4efb-b4bc-ff3082b2f6fe","html_url":"https://github.com/NikSativa/SmartNetwork","commit_stats":null,"previous_names":["niksativa/nrequest"],"tags_count":149,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FSmartNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FSmartNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FSmartNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikSativa%2FSmartNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NikSativa","download_url":"https://codeload.github.com/NikSativa/SmartNetwork/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249031814,"owners_count":21201357,"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":["api","async-await","auth","curl","fast","interception","interceptor","ios","json","mac","macos","plugin","request","rest","stoptheline","strongly-typed","swift","urlsession","visionos","watchos"],"created_at":"2025-02-07T05:29:10.800Z","updated_at":"2025-10-16T18:23:39.333Z","avatar_url":"https://github.com/NikSativa.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SmartNetwork\n\n[![Swift Versions](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FNikSativa%2FSmartNetwork%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/NikSativa/SmartNetwork)\n[![Supported Platforms](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FNikSativa%2FSmartNetwork%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/NikSativa/SmartNetwork)\n[![CI](https://github.com/NikSativa/SmartNetwork/actions/workflows/swift_macos.yml/badge.svg)](https://github.com/NikSativa/SmartNetwork/actions/workflows/swift_macos.yml)\n[![License](https://img.shields.io/github/license/Iterable/swift-sdk)](https://opensource.org/licenses/MIT)\n\n**SmartNetwork** is a lightweight, developer-friendly networking library for Swift. It wraps `URLSession` in a clean and flexible API that’s fully compatible with Swift Concurrency. Whether you’re into `async/await` or prefer trusty closures, SmartNetwork helps you build robust, testable network layers—without all the boilerplate.\n\n---\n\n## ✨ Features\n\n- Clean, strongly typed networking using `Decodable`.\n- Supports both `async/await` and closure-based APIs.\n- Built-in decoding for common response types:\n  - `Void` — when you don’t expect data back.\n  - `Data` — raw binary responses.\n  - `Decodable` — your custom models.\n  - `UIImage` (or `NSImage`) — image fetching made easy.\n  - `Any` — raw JSON as dictionaries or arrays.\n- Custom decoding support with the `Deserializable` protocol.\n- Decode deeply nested JSON with `keyPath`.\n- Plugin system for logging, auth, request mutation, and more.\n- Control request lifecycles via `SmartTask`.\n- Built-in stubbing support for reliable, isolated tests.\n\n---\n\n## 🚀 Usage\n\nSmartNetwork offers multiple styles for making requests, allowing you to choose what best fits your coding style or project needs.\n\n### 🔹 Async/await\n\nPerform a request using Swift's modern concurrency syntax:\n\n```swift\nlet result = await manager.decodable.request(TestInfo.self, address: address)\n```\n\n### 🔹 Closure-based\n\nUse completion handlers for backward compatibility or callback-driven workflows:\n\n```swift\nmanager.decodable.request(TestInfo.self, address: address) { result in\n    // Handle result here\n}.start()\n```\n\n### 🔹 Fluent chainable API\n\nConstruct readable, chainable network calls using SmartNetwork’s fluent API:\n\n```swift\nlet result = await manager.request(address: address).decodeAsync(TestInfo.self)\n```\n\n```swift\nmanager.request(address: address)\n    .decode(TestInfo.self)\n    .complete { result in\n        // Handle result here\n    }\n    .detach()\n    .deferredStart()\n```\n\nThese patterns offer flexibility whether you're building simple calls or need more granular control over the request lifecycle.\n\n---\n\n## 🧩 Plugin system\n\nSmartNetwork includes a modular plugin system that allows you to customize and extend networking behavior without changing core logic. Plugins can be used to modify requests, inspect responses, or enforce specific policies.\n\nHere are some built-in plugins you can use:\n\n- `Plugins.StatusCode` – Validates HTTP status codes and can trigger custom error handling.\n- `Plugins.Basic`, `Plugins.Bearer` – Easily apply Basic or Bearer authentication headers.\n- `Plugins.TokenPlugin` – Inject custom tokens via headers or query parameters.\n- `Plugins.Log`, `Plugins.LogOS` – Output curl-style debug logs or use system logging.\n- `Plugins.JSONHeaders` – Automatically adds `Content-Type` and `Accept` headers for JSON APIs.\n- `PluginPriority` – Define the order in which plugins execute.\n- `StopTheLine` – Temporarily blocks all requests (e.g. during token refresh or maintenance).\n\nYou can combine and prioritize plugins to precisely control the behavior of your networking pipeline.\n\n---\n\n## 🔧 Custom decoding\n\nYou can define types that include a decoding key path for nested JSON parsing:\n\n```swift\nprotocol KeyPathDecodable {\n    associatedtype Response: Decodable\n    static var keyPath: [String] { get }\n}\n\nextension SmartRequestManager {\n    func keyPathed\u003cT: KeyPathDecodable\u003e(_ type: T.Type = T.self) -\u003e TypedRequestManager\u003cT.Response?\u003e {\n        return custom(KeyPathDecodableContent\u003cT\u003e())\n    }\n}\n```\n\n---\n\n## 🧪 Testing\n\nSmartNetwork makes it easy to write fast, isolated unit tests with support for stubbing and mocking via `HTTPStubServer` and [`SpryKit`](https://github.com/NikSativa/SpryKit).\n\n---\n\n## 🖼️ Image loading\n\nNeed to fetch and display images? Pair SmartNetwork with [`SmartImages`](https://github.com/NikSativa/SmartImages) for async image loading support.\n\n---\n\n## 📚 Documentation\n\n- [SmartNetwork Overview (PDF)](./.instructions/SmartNetwork.pdf)  \n  \u003cimg src=\"./.instructions/SmartNetwork.jpg\" alt=\"SmartNetwork Overview Preview\" width=\"300\" /\u003e\n\n- [Plugins Behavior (PDF)](./.instructions/Plugins_behavior.pdf)  \n  \u003cimg src=\"./.instructions/Plugins_behavior.jpg\" alt=\"Plugins Behavior Preview\" width=\"300\" /\u003e\n\n---\n\n## 📦 Installation\n\nTo add SmartNetwork to your project via Swift Package Manager:\n\n```swift\n.package(url: \"https://github.com/NikSativa/SmartNetwork.git\", from: \"5.0.0\")\n```\n\nThen, add `\"SmartNetwork\"` to your target dependencies.\n\n---\n\n## 📄 License\n\n`SmartNetwork` is available under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksativa%2Fsmartnetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniksativa%2Fsmartnetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksativa%2Fsmartnetwork/lists"}