{"id":1658,"url":"https://github.com/ThreeGayHub/SolarNetwork","last_synced_at":"2025-08-06T14:31:14.123Z","repository":{"id":62455781,"uuid":"96204667","full_name":"ThreeGayHub/SolarNetwork","owner":"ThreeGayHub","description":"Elegant network abstraction layer in Swift.","archived":false,"fork":false,"pushed_at":"2020-03-30T13:55:47.000Z","size":224,"stargazers_count":102,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-21T22:04:35.748Z","etag":null,"topics":["alamofire","network","networking","swift"],"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/ThreeGayHub.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":"2017-07-04T10:09:53.000Z","updated_at":"2024-09-22T16:47:50.000Z","dependencies_parsed_at":"2022-11-02T01:01:28.701Z","dependency_job_id":null,"html_url":"https://github.com/ThreeGayHub/SolarNetwork","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThreeGayHub%2FSolarNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThreeGayHub%2FSolarNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThreeGayHub%2FSolarNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ThreeGayHub%2FSolarNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ThreeGayHub","download_url":"https://codeload.github.com/ThreeGayHub/SolarNetwork/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905546,"owners_count":17989781,"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":["alamofire","network","networking","swift"],"created_at":"2024-01-05T20:15:52.515Z","updated_at":"2024-12-09T14:31:15.999Z","avatar_url":"https://github.com/ThreeGayHub.png","language":"Swift","funding_links":[],"categories":["Networking","Libs","Network [🔝](#readme)"],"sub_categories":["Video","Network","Other free courses"],"readme":"# ![SLNetwork](SLNetwork.png)\n\n![CocoaPods Compatible](https://img.shields.io/cocoapods/v/SolarNetwork.svg) ![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)  ![Platform](https://img.shields.io/cocoapods/p/SolarNetwork.svg?style=flat)\n\nElegant network abstraction layer in Swift.\n\n\n\n- [中文](ChineseREADME.md)\n- [Design](#design)\n- [Features](#features)\n- [Requirements](#requirements)\n- [Communication](#communication)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Base Usage](#base-usage) - [Target](#target) - [Request](#request) - [Download](#download) - [Upload](#upload) - [Decode](#decode)\n  - [Target](Documentation/Target.md) - Configuration of a Host.\n  - [Request](Documentation/Request.md) - Configuration of a DataRequest.\n  - [Download](Documentation/Download.md) - Configuration of a DownloadRequest or ResumeDownloadRequest.\n  - [Upload](Documentation/Upload.md) - Configuration of a UploadRequest(Data - File - InputStream - FormData).\n  - [Progress](Documentation/Progress.md) - Progress\n  - [Response](Documentation/Response.md) - Decode - Error\n  - [Plugin](Documentation/Plugin.md) - WillSend - DidReceive\n- [License](#license)\n- [UpdateLog](Documentation/UpdateLog.md)\n\n---\n\n# Design\n\n**[Alamofire](https://github.com/Alamofire/Alamofire)** and **[Moya](https://github.com/Moya/Moya)** are elegant Swift network frames. They each have their own advantages. When I use them, I always want to combine the advantages of both, make them easy to use and retain their original features. So I wrote the **SolarNetwork**.\n\n- **SLNetwork** corresponds to a SessionManager.\n- **SLTarget** corresponds to a Host, or a set of requests for the same configuration.\n- **SLRequest**, **SLDownloadRequest**, **SLUploadRequest** corresponds to Request of Data, Download, Upload.\n- **SLProgress** return progress when download or upload.\n- **SLResponse** response of a request which you can decode to JsonObject or Model.\n- **SLPlugin** you can modify SLRequest in `willSend` and modify SLResponse in `didReceive`.\n- **SLReflection** reflex properties of SubSLRequest to Alamofire.Parameters.\n\nSo a complete request process is:\n\n```swift\nSLNetwork(SLTarget).request(SLRequest).willSend(SLRequest)\n                   .progressClosure(SLProgress)\n                   .reponseData(OriginalResponse)\n                   .didReceive(SLResponse).decodeTo(Dictionary)\n                   .completionClosure(SLResponse)\n                   .decodeTo(Model: Decodable).dealWithError\n```\n\nIn most cases, what you need to concerned about is:\n\n```swift\nSLNetwork(SLTarget).request(SLRequest)\n                   .progressClosure(SLProgress)\n                   .completionClosure(SLResponse)\n```\n\n---\n\n# Features\n\n- [x] URL / JSON / plist Parameter Encoding\n- [x] Upload File / Data / Stream / MultipartFormData\n- [x] Download File using Request or Resume Data\n- [x] Authentication with URLCredential\n- [x] Upload and Download Progress Closures with Progress\n- [x] Dynamically Adapt and Retry Requests\n- [x] TLS Certificate and Public Key Pinning\n- [x] Network Reachability\n- [x] Pre-populate the DNS cache\n- [x] Complete Logger\n\n---\n\n## Requirements\n\n- iOS 8.0+\n- Xcode 9+\n- Swift 4+\n\n---\n\n## Communication\n\n- If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/alamofire).\n- If you **found a bug**, open an issue.\n- If you **have a feature request**, open an issue.\n- If you **want to contribute**, submit a pull request.\n\n---\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\n\u003e CocoaPods 1.1+ is required.\n\nTo integrate SolarNetwork into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\nuse_frameworks!\n\ntarget '\u003cYour Target Name\u003e' do\n    pod 'SolarNetwork'\nend\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate Alamofire into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"ThreeGayHub/SolarNetwork\"\n```\n\nRun `carthage update` \n\nIf this is your first time using Carthage in the project, you'll need to go through some additional steps as explained [over at Carthage](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application).\n\n---\n\n# Usage\n\n## Base Usage\n\n### Target\n\n```swift\nimport SolarNetwork\n\nstruct HTTPBinTarget: SLTarget {\n    var baseURLString: String { return \"https://httpbin.org\" }\n}\n\nlet HTTPBinNetwork = SLNetwork(HTTPBinTarget())\n```\n\n### Request\n\n```swift\nimport SolarNetwork\n\n//Mark: - GET\nclass HTTPBinGETRequest: SLRequest {\n    \n    override func loadRequest() {\n        super.loadRequest()\n        \n        self.path = \"/get\"\n    }\n    \n}\n\nHTTPBinNetwork.request(HTTPBinGETRequest()) { (response) in\n    if let dictionary = response.dataDictionary {\n                        \n    }\n    else if let error = response.error {\n        //show error\n    }\n}\n\n//Mark: - POST\nclass HTTPBinPOSTRequest: SLRequest {\n    \n    override func loadRequest() {\n        super.loadRequest()\n        \n        self.method = .post\n        self.path = \"/post\"\n    }\n    \n    /**\n     properties will encode to parameters by Reflection\n     [\"userName\": \"myUserName\",\n      \"password\": \"myPassword\",\n\t  \"name\" : \"youName\"]\n     */\n    let userName = \"myUserName\"\n    let password = \"myPassword\"\n\t\n    var name: String?\n}\n\nlet postReq = HTTPBinPOSTRequest()\npostReq.name = \"yourName\"\nHTTPBinNetwork.request(postReq) { (response) in\n    if let dictionary = response.dataDictionary {\n                        \n    }\n    else if let error = response.error {\n        //show error\n    }\n}\n```\n\n### Download\n\n```swift\nimport SolarNetwork\n\nclass HTTPBinDownLoadRequest: SLDownloadRequest {\n    \n    override func loadRequest() {\n        super.loadRequest()\n        \n        self.path = \"/image/png\"\n        self.isResume = true //control the download request is resume or not, default is false\n    }\n}\n\nHTTPBinNetwork.download(HTTPBinDownLoadRequest(), progressClosure: { (progress) in\n                    \n}) { (resposne) in\n                    \n}\n\n```\n\n### Upload\n\n```swift\nimport SolarNetwork\n\nclass HTTPBinUploadRequest: SLUploadRequest {\n    \n    override func loadRequest() {\n        super.loadRequest()\n        \n        self.path = \"/post\"\n    }\n    \n}\n\nlet uploadRequest = HTTPBinUploadRequest()\nuploadRequest.data = data //data to upload\nHTTPBinNetwork.upload(uploadRequest, progressClosure: { (progress) in\n                            \n}) { (response) in\n                            \n}\n```\n\n### Decode\n\nIn Swift 4, you can use Codable.\n\n```swift\nimport SolarNetwork\n\nstruct User: Decodable { //Swift 4 Codable\n    var id: Int\n    var name: String\n    var token: String\n}\n\nHTTPBinNetwork.request(UserRequest()) { (response) in\n    if let user = response.decode(to: User.self) {\n                        \n    }\n    else if let error = response.error {\n        //show error\n    }\n}\n```\n\n\n\n---\n\n## License\n\nAlamofire is released under the MIT license. [See LICENSE](https://github.com/ThreeGayHub/SolarNetwork/blob/master/LICENSE) for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThreeGayHub%2FSolarNetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FThreeGayHub%2FSolarNetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FThreeGayHub%2FSolarNetwork/lists"}