{"id":16957849,"url":"https://github.com/pauljohanneskraft/asyncnetwork","last_synced_at":"2025-04-11T21:52:29.011Z","repository":{"id":45401774,"uuid":"513491754","full_name":"pauljohanneskraft/AsyncNetwork","owner":"pauljohanneskraft","description":"Lightweight async/await networking library with interceptor support - usable from iOS 13+.","archived":false,"fork":false,"pushed_at":"2022-09-30T13:51:39.000Z","size":47,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T21:52:24.456Z","etag":null,"topics":["async-await","foundation","network","swift","swift-async","swift-foundation","urlsession"],"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/pauljohanneskraft.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":"2022-07-13T11:19:57.000Z","updated_at":"2022-10-04T04:41:21.000Z","dependencies_parsed_at":"2023-01-18T18:17:29.823Z","dependency_job_id":null,"html_url":"https://github.com/pauljohanneskraft/AsyncNetwork","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauljohanneskraft%2FAsyncNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauljohanneskraft%2FAsyncNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauljohanneskraft%2FAsyncNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauljohanneskraft%2FAsyncNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pauljohanneskraft","download_url":"https://codeload.github.com/pauljohanneskraft/AsyncNetwork/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487733,"owners_count":21112188,"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":["async-await","foundation","network","swift","swift-async","swift-foundation","urlsession"],"created_at":"2024-10-13T22:20:10.794Z","updated_at":"2025-04-11T21:52:28.985Z","avatar_url":"https://github.com/pauljohanneskraft.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://user-images.githubusercontent.com/15239005/178734626-93f21b81-3072-498f-be01-13d4e459f587.png\" width=50%\u003e\nLightweight async/await networking library with interceptor support.\n\n## 🚀 Getting started\n\n`AsyncNetwork`'s session acts as a wrapper to [`URLSession`](https://developer.apple.com/documentation/foundation/urlsession) by adding support for interceptors. Interceptors can be used to easily extract common functionality for the preparation of [`URLRequests`](https://developer.apple.com/documentation/foundation/urlrequest) and the handling or retrying of the respective responses. This library allows you to write custom interceptors, but also comes with a couple of handy interceptors for authentication, status code validation, adding custom headers, logging and more!\n\nLet's see how we can make use of that.\n\n```swift\nlet session = Session(\n    session: .shared,\n    interceptors: [\n        .setHeaders { headers in\n            headers[\"Accept-Language\"] = Locale.current.languageCode\n            headers[\"Accept-Type\"] = \"application/json\"\n            headers[\"Content-Type\"] = \"application/json\"\n        },\n        .validateStatus(),\n        .dataResponseLogger(),\n    ],\n    maximumRetryCount: 1,\n)\n```\n\nIn the code example above, a `Session` is created on the basis of an underlying [`URLSession`](https://developer.apple.com/documentation/foundation/urlsession) and an array of interceptors. Interceptors can be thought of as layers, as they are called in order during request preparation and in reverse order for handling the response.\n\nThe first interceptor sets a set of headers, so that each request contains the correct \"Accept-Language\", \"Accept-Type\" and \"Content-Type\" header fields. In this example, we are overriding existing headers, which we might not always want to do, so you might want to have a look at `.addHeaders` instead.\n\nThe second interceptor validates that the status code of the response is between 200 and 299. If not, it throws an error and makes the whole request fail based on that. Successive interceptors (in this case, the one above it, which is not doing anything for response handling anyways), will not be called due to the error being thrown.\n\nThe third and last interceptor logs the response of every request response to the console. You can modify `subsystem`, `category` and `logType` as well here, if you want to customize that output. For even more control, you might want to look into the more general `.logger` interceptor as well.\n\n## 🔩 Installation\n\nAsyncNetwork is currently only available via Swift Package Manager. See [this tutorial by Apple](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) on how to add a package dependency to your Xcode project.\n\n## ✍️ Author\n\nPaul Kraft\n\n## 📄 License\n\nAsyncNetwork is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauljohanneskraft%2Fasyncnetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpauljohanneskraft%2Fasyncnetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauljohanneskraft%2Fasyncnetwork/lists"}