{"id":32150654,"url":"https://github.com/swiftyjoeyy/swift-networking","last_synced_at":"2026-06-04T02:31:06.825Z","repository":{"id":251813713,"uuid":"769636338","full_name":"SwiftyJoeyy/swift-networking","owner":"SwiftyJoeyy","description":"✨ A fully declarative Swift networking library inspired by SwiftUI and macros. Build expressive, composable, and testable network requests with ease.","archived":false,"fork":false,"pushed_at":"2025-12-24T09:20:02.000Z","size":664,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-11T17:26:26.813Z","etag":null,"topics":["actors","async-await","concurrency","declarative","macros","networking","ssl-pinning","swift","urlsession"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/SwiftyJoeyy/swift-networking","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SwiftyJoeyy.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":"2024-03-09T16:25:34.000Z","updated_at":"2026-01-06T19:52:56.000Z","dependencies_parsed_at":"2024-11-14T19:24:40.138Z","dependency_job_id":"9eb28f8c-1470-4633-b52c-d0005ec0afdd","html_url":"https://github.com/SwiftyJoeyy/swift-networking","commit_stats":null,"previous_names":["buildexperience/networkkit","swiftyjoeyy/networkkit","swiftyjoeyy/swift-networking"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/SwiftyJoeyy/swift-networking","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftyJoeyy%2Fswift-networking","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftyJoeyy%2Fswift-networking/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftyJoeyy%2Fswift-networking/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftyJoeyy%2Fswift-networking/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SwiftyJoeyy","download_url":"https://codeload.github.com/SwiftyJoeyy/swift-networking/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftyJoeyy%2Fswift-networking/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29608152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T06:47:36.664Z","status":"ssl_error","status_checked_at":"2026-02-19T06:45:47.551Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["actors","async-await","concurrency","declarative","macros","networking","ssl-pinning","swift","urlsession"],"created_at":"2025-10-21T10:14:40.661Z","updated_at":"2026-02-19T08:01:51.452Z","avatar_url":"https://github.com/SwiftyJoeyy.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub Release](https://img.shields.io/github/release/SwiftyJoeyy/swift-networking.svg?include_prereleases)](https://github.com/SwiftyJoeyy/swift-networking/releases)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FSwiftyJoeyy%2Fswift-networking%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/SwiftyJoeyy/swift-networking)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FSwiftyJoeyy%2Fswift-networking%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/SwiftyJoeyy/swift-networking)\n[![License](https://img.shields.io/github/license/SwiftyJoeyy/swift-networking)](https://github.com/SwiftyJoeyy/swift-networking/blob/main/LICENSE)\n[![Swift](https://github.com/SwiftyJoeyy/swift-networking/actions/workflows/swift.yml/badge.svg)](https://github.com/SwiftyJoeyy/swift-networking/actions/workflows/swift.yml)\n\n# Swift Networking\n\n**Swift Networking** is a modern Swift networking library built entirely around a **declarative programming model**. From defining requests to configuring clients and handling responses, everything is expressed clearly and fluentlyy.\n\nInspired by **Swift** \u0026 **SwiftUI**’s design philosophy, it allows you to define network behavior in a way that is readable, modular, and test-friendly — all while keeping boilerplate to a minimum.\n\n\n\n## ✨ Highlights\n\n- 🧾 **Fully declarative** request \u0026 response design  \n- ⚙️ Custom clients, interceptors, headers, and parameters via DSL  \n- 🔄 Built-in support for request/response modifiers and interceptors\n- 🧪 Easy-to-test and modular architecture  \n- 🧰 Modular, extensible architecture\n\n\n\n## 🚀 Getting Started\n\nThis guide walks you through the core building blocks:\n1. Defining a request.\n2. Adding headers, parameters, and body.\n3. Building a client.\n4. Sending a request.\n\n\n### 1. Defining a request\nTo define a request, use the [`@Request`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/request(_:)) macro. This adds conformance to the [`Request`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/request) protocol, which requires a `request` property similar to SwiftUI’s body.\nInside that property, you start with an [`HTTPRequest`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/httprequest), which represents the core of the request.\n\nYou can:\n\n- Provide a url to override the client’s base URL\n- Add an optional path\n- Set the HTTP method using [`method(_:)`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/request/method(_:))\n- Append extra path components using [`appending(_:)`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/request/appending(_:))\nExample\n\n```swift\n@Request struct TestingRequest {\n    var request: some Request {\n        HTTPRequest(url: \"https://www.example.com\", path: \"gallery\")\n            .method(.get)\n            .appending(\"cats\", \"images\")\n    }\n}\n```\nThis creates a simple GET request to `https://www.google.com/test/cats/images`.\n\nYou can also compose and override requests:\n\n```swift\n@Request struct TestRequest {\n    @Header var test: String {\n        return \"Computed\"\n    }\n    var request: some Request {\n        TestingRequest() // TestingRequest instead of HTTPRequest\n            .timeout(90)\n            .method(.post)\n    }\n}\n```\n\n\n### 2. Adding Headers, Parameters, and Body\n\n`Networking` offers multiple ways to add headers, query parameters, and request bodies. You can use macros for top level values or chaining modifiers for inline customization.\n\n#### 🧩 Adding Parameters\n\nUse [`Parameter`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/parameter) to create parameters from `String`, `Int`, `Double`, or `Bool` values, including arrays of those types.\nYou can also use [`ParametersGroup`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/parametersgroup) to group multiple parameters into one modifier.\n\nTo add parameters to a request, you use the [`@Parameter`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/parameter(_:)) macro, or dynamically through modifier methods:\n\n```swift\n@Request struct SearchRequest {\n    @Parameter var query: String // Using the name of the property\n    @Parameter(\"search_query\") var query: String // Using a custom name.\n    let includeFilter: Bool\n    var request: some Request {\n        HTTPRequest(path: \"search\")\n            .appendingParameters {\n                Parameter(\"query\", value: \"cats\")\n                if includeFilter {\n                    Parameter(\"filter\", value: \"popular\")\n                }\n            }.appendingParameter(\"sorting\", value: \"ascending\")\n            .appendingParameter(\"filters\", values: [\"new\", \"free\"])\n    }\n}\n```\n\n#### 📬 Adding Headers\n\nUse [`Header`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/header) to define headers from `String`, `Int`, `Double`, or `Bool` values.\nYou can also use [`HeadersGroup`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/headersgroup) if you want to group multiple headers in a single modifier, or inject a raw dictionary `[String: String]`.\nYou also get convenience types like: [`AcceptLanguage`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/acceptlanguage), [`ContentDisposition`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/contentdisposition) \u0026 [`ContentType`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/contenttype).\nSimilar to parameters, headers can also be declared statically using the [`@Header`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/header(_:)) macro or applied dynamically using modifiers:\n\n```swift\n@Request struct AuthenticatedRequest {\n    @Header var token: String // Using the name of the property.\n    @Header(\"Authorization\") var token: String // Using a custom name.\n    let includeLang: Bool\n    var request: some Request {\n        HTTPRequest(path: \"me\")\n            .additionalHeaders {\n                Header(\"Custom-Header\", value: \"value\")\n                if includeLang {\n                    AcceptLanguage(\"en\")\n                }\n            }.additionalHeader(\"version\", value: \"1.0\")\n    }\n}\n```\n\n#### 📦 Adding a Request Body\n\nCurrently, `Networking` supports [`JSON`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/json) and [`FormData`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/formdata) request bodies.\nTo apply a body to a request, you can use the [`body(_:)`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/request/body(_:)) modifier, or convenience modifiers for `json`:\n\n##### ✅ Using .body(...) Modifier\n\n```swift\nHTTPRequest(path: \"upload\")\n    .body {\n        // JSON\n        JSON([\"dict\": \"data\"]) // Dictionary\n        JSON(Data()) // Raw data.\n        JSON(EncodableUser()) // Encodable types.\n\n        // FormData\n        FormData {\n            FormDataBody( /// Raw data\n                \"Image\",\n                data: Data(),\n                fileName: \"image.png\",\n                 mimeType: .png\n            )\n            FormDataFile( // Data from a file.\n                \"File\",\n                fileURL: URL(filePath: \"filePath\"),\n                fileName: \"file\",\n                 mimeType: .fileURL\n            )\n        }\n    }\n```\n\n##### ✅ Using JSON Convenience Modifiers\n```swift\nHTTPRequest(path: \"create\")\n    .json([\"name\": \"John\", \"age\": 30]) // Dictionary.\n    .json(Data()) // Raw data.\n    .json(EncodableUser()) // Encodable types.\n```\n\u003e [!CAUTION]\n\u003e If multiple `.body()` or `.json()` modifiers are used, the last one overrides the previous. This applies to all modifiers, modifier order matters.\n\n#### 🧱 Inline Modifiers with HTTPRequest\n\nYou can also include modifiers directly in the `HTTPRequest` initializer. This gives you a clean, SwiftUI style declaration for most common request scenarios.\n\n```swift\nHTTPRequest(path: \"submit\") {\n    Header(\"X-Token\", value: \"123\")\n    Parameter(\"query\", value: \"swift\")\n    JSON([\"key\": \"value\"])\n}\n```\n\n\n### 3. Building a client\n\nTo define a networking client, use the [`@Client`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/client()) macro. This macro adds conformance to the [`NetworkClient`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/networkclient) protocol, which requires a `session` property. This property returns a [`Session`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/session) instance that describes how your requests should be configured and executed.\n\n\u003e [!IMPORTANT]\n\u003e Do not call the session property directly. It’s a computed property that creates a new session each time it’s accessed.\n\u003e Always send requests using the client instance itself (e.g. try await client.dataTask(...)).\n\u003e You should also hold on to the client instance created either using a singleton or by dependency injection to avoid creating multiple instances.\n\nInside the session property, you can create and customize a `Session` using a closure that returns a configured `URLSessionConfiguration`.\nFrom there, you can apply additional behaviors such as Base URL, Logging, Retry policy, Authorization, Response validation, Encoding/decoding strategies.\n\n```swift\n@Client struct MyClient {\n    var session: Session {\n        Session {\n            URLSessionConfiguration.default\n                .urlCache(.shared)\n                .requestCachePolicy(.returnCacheDataElseLoad)\n                .timeoutIntervalForRequest(90)\n                .timeoutIntervalForResource(90)\n                .httpMaximumConnectionsPerHost(2)\n                .waitForConnectivity(true)\n                .headers {\n                    Header(\"Key\", value: \"Value\")\n                }\n        }\n        .authorization(BearerAuthProvider())\n        .baseURL(\"https://example.com\")\n        .decode(with: JSONDecoder())\n        .encode(with: JSONEncoder())\n        .retry(limit: 2, delay: 2)\n        .enableLogs(true)\n        .validate(for: [.badGateway, .created])\n    }\n}\n```\n\n#### ⚙️ Custom Configuration Values\n\nYou can define custom configuration keys using the [`@Config`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/config(forceunwrapped:)) macro \u0026 extending [`ConfigurationValues`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/configurationvalues):\n\n```swift\nextension ConfigurationValues {\n    @Config var customConfig = CustomValue()\n}\n```\n\nThen, you can set it on a task or on the session using the modifier [`configuration(_:_:)`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/configurable/configuration(_:_:)):\n\n```swift\n@Client struct MyClient {\n    var session: Session {\n        Session()\n            .configuration(\\.customConfig, CustomValue())\n    }\n}\n\nlet data = try await client.dataTask(TestingRequest())\n    .configuration(\\.customConfig, CustomValue())\n    .response()\n```\n\nThis allows you to define project-specific config values and inject them anywhere in your request or session pipeline.\n\n\n### 4. Sending a request\n\nTo send a request, you start by creating a task from a client. The framework provides two main types of tasks:\n- [`dataTask`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/session/datatask(_:)) — for requests that return data.\n- [`downloadTask`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/session/downloadtask(_:)) — for file downloads.\n  \nEach task can be configured individually using the same modifiers available on `Session` (e.g. retry, decoding, etc.), giving you full control per request.\n\n```swift\nlet task = MyClient()\n    .dataTask(MyRequest())\n    .retry(limit: 2)\n    .validate(for: [.ok, .notModified])\n```\n\nTo start a task you either call [`resume()`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/networkingtask/resume()) manually, or access the response directly (recommended) using [`response()`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/networktask/response()) or decode it to a specific type using [`decode(as:)`](https://swiftpackageindex.com/swiftyjoeyy/swift-networking/main/documentation/networking/datatask/decode(as:))\n\n```swift\nlet task = MyClient().dataTask(MyRequest())\n\ntask.resume()\nlet result = try await task.response()\nlet user = try await task.decode(as: User.self)\n```\n\n\u003e [!NOTE]\n\u003e A task will only send the request once.\n\u003e If `response()` or `decode(as:)` is called multiple times, the framework will await the result of the first call instead of resending the request.\n\n\n\n## 📦 Installation\n\nAdd via **Swift Package Manager**:\n\n```swift\n.package(url: \"https://github.com/SwiftyJoeyy/swift-networking.git\", from: \"1.0.0\")\n```\n\nThen add `\"Networking\"` to your target dependencies.\n\n\n\n## 🛣️ Planned Features\n\nThese enhancements are planned for future releases of `Networking` to further improve flexibility, control, and developer experience:\n\n- 🪄 Simplified Request API\nQuick request execution using a default client instance for lightweight use cases.\n\n- 🔄 Resumable Downloads\nSupport for partial downloads and automatic resume handling across app launches or interruptions.\n\n- 📤 Upload Task Support\nUpload data or files with progress tracking, cancellation, and retry support.\n\n- 🏷️ Request Tagging\nTag and categorize requests into logical groups for analytics, cancellation, debugging, and tracing.\n\n- 🧪 Built-in Testing Support\nTools for mocking, stubbing, and asserting requests and responses with zero boilerplate.\n\n- 🔄 Request Execution \u0026 Prioritization\nControl request flow with custom executors, in-flight limits, and per-task priority that can escalate or drop dynamically.\n\n- 📽 Request Recording \u0026 Playback\nCapture and replay real request traffic for debugging, offline development, and test validation.\n\n\n\n## 📖 Documentation\n\nThe [documentation](https://swiftpackageindex.com/SwiftyJoeyy/swift-networking/main/documentation/networking) is provided by [swiftpackageindex](https://swiftpackageindex.com).\n\n\n\n## 📄 License\n\nLicensed under the Apache 2.0 License. See the [LICENSE](https://github.com/SwiftyJoeyy/swift-networking/blob/refactored/LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftyjoeyy%2Fswift-networking","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiftyjoeyy%2Fswift-networking","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftyjoeyy%2Fswift-networking/lists"}