{"id":16381000,"url":"https://github.com/jasl/moyax","last_synced_at":"2025-03-16T16:30:35.484Z","repository":{"id":56935230,"uuid":"50410305","full_name":"jasl/MoyaX","owner":"jasl","description":"Network abstraction layer written in Swift, based on Moya","archived":false,"fork":false,"pushed_at":"2016-10-05T13:10:28.000Z","size":5817,"stargazers_count":77,"open_issues_count":2,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-12T03:53:08.279Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jasl.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":"2016-01-26T07:03:51.000Z","updated_at":"2024-04-11T11:14:11.000Z","dependencies_parsed_at":"2022-11-29T13:20:33.471Z","dependency_job_id":null,"html_url":"https://github.com/jasl/MoyaX","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2FMoyaX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2FMoyaX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2FMoyaX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasl%2FMoyaX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasl","download_url":"https://codeload.github.com/jasl/MoyaX/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221665765,"owners_count":16860309,"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":[],"created_at":"2024-10-11T03:53:06.563Z","updated_at":"2024-10-27T10:53:49.041Z","avatar_url":"https://github.com/jasl.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"MoyaX - a fork of [Moya](https://github.com/Moya/Moya)\n====\n\n[![Build Status](https://travis-ci.org/jasl/MoyaX.svg?branch=master)](https://travis-ci.org/jasl/MoyaX)\n[![codecov.io](https://codecov.io/github/jasl/MoyaX/coverage.svg?branch=master)](https://codecov.io/github/jasl/MoyaX?branch=master)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/MoyaX.svg)](https://img.shields.io/cocoapods/v/MoyaX.svg)\n[![Platform](https://img.shields.io/cocoapods/p/Alamofire.svg?style=flat)](http://cocoadocs.org/docsets/MoyaX)\n\n[中文版本介绍](Readme_zh.md)\n\n**MoyaX all features are freezed, it still needs more tests, documents and code reviews, please help!**\n\nYou're a smart developer. You probably use Alamofire to abstract away access to NSURLSession and all those nasty details you don't really care about. But then, like lots of smart developers, you write ad hoc network abstraction layers. They are probably called \"APIManager\" or \"NetworkModel\", and they always end in tears.\n\nSo the basic idea of Moya is that we want some network abstraction layer that sufficiently encapsulates actually calling Alamofire directly. It should be simple enough that common things are easy, but comprehensive enough that complicated things are also easy.\n\nAlso MoyaX treats test stubs as first-class citizens so unit testing is super-easy.\n\nMoyaX forked Moya originally, but with many refactors, MoyaX has great difference with Moya including:\n\n- Targets no strict using `enum`\n- Support MultipartFormData upload\n- Expose Alamofire's `Request` and `Response` for advanced usage\n- More powerful stubbing request\n\nBut MoyaX consider functional and reactive support should become extension, so they'd been removed for now until MoyaX is stable.\n\n## Sample Project\n\nThere's a sample project in the `Example` directory. Have fun!\n\n## Requirements\n\n- iOS 8.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+\n- Xcode 7.3+\n\n## Installation\n\n### CocoaPods\n\nJust add `pod 'MoyaX'` to your Podfile and go!\n\nThen run `pod install`.\n\n### Carthage\n\nCarthage users can point to this repository\n\n```\ngithub \"jasl/MoyaX\"\n```\n\n## Getting start\n\n### Abstract restful API into a target\n\nUsing MoyaX starts with defining a target – it could be a `struct`, `class` or an `enum` that requires to conform to the `Target` protocol. Then, the rest of your app deals *only* with those targets. a Target is looks like:\n\n```swift\n// This struct defined Github show user API\nstruct GithubShowUser: Target {\n  // The username which should requesting\n  let name: String\n  \n  // Constructor\n  init(name: String) {\n    self.name = name\n  }\n  \n  // Required\n  var baseURL: NSURL {\n    return NSURL(string: \"https://api.github.com\")!\n  }\n  \n  // Required\n  var path: String {\n    return \"/users/\\(name)\"\n  }\n  \n  // Optional, default is .GET\n  var method: HTTPMethod {\n    return .get\n  }\n  \n  // Optional, default is empty\n  var headerFields: [String: String] {\n    return [:]\n  }\n  \n  // Optional, default is empty\n  var parameters: [String: AnyObject] {\n    return [:]\n  }\n  \n  // Optional, default is .URL, means submitting parameters using `x-www-form-urlencoded`\n  var parameterEncoding: ParameterEncoding {\n    return .url\n  }\n}\n```\n\n### Making a request\n\nYou should access Targets through `MoyaXProvider`.\n\n```swift\n// Initialize a MoyaXProvider\nlet provider = MoyaXProvider()\n\n// Request an API\nprovider.request(GithubShowUser(name: \"jasl\")) { response in\n  switch response {\n  \n  // The server has response, 4xx and 5xx goes here too\n  case let .response(response):\n    let data = response.data\n    let statusCode = response.statusCode\n    // Handle success here\n    \n  // Network failure (connectivity or timeout), the request had cancelled or other unexpected errors goes here\n  case let .incomplete(error):\n    // error is an enum\n    // Handle error here\n  }\n}\n```\n\n### Uploading MultipartFormData\n\nUploading MultipartFormData is simple and efficient.\n\n```swift\nstruct UploadingTarget: Target {\n  let baseURL = NSURL(string: \"https://httpbin.org\")!\n  let path = \"post\"\n  \n  // Remember, .get doesn't support uploading.\n  let method = HTTPMethod.post\n\n  // Encoding parameters by multipart/form-data\n  let parameterEncoding = ParameterEncoding.multipartFormData\n\n  var parameters: [String: AnyObject] {\n    return [\n      // MoyaX provides some placeholders for MultipartFormData\n      \"photo1\": FileForMultipartFormData(fileURL: photoFileURL, filename: 'photo1.jpg', mimeType: 'image/jpeg'),\n      \"photo2\": DataForMultipartFormData(data: photoData, filename: 'photo2.jpg', mimeType: 'image/jpeg')\n  }\n}\n\n// Request a MultipartFormData target is no different with others.\nprovider.request(UploadingTarget()) { response in\n  // Handle response\n}\n``` \n\n## License\n\nMoyaX is released under an MIT license. See LICENSE for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasl%2Fmoyax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasl%2Fmoyax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasl%2Fmoyax/lists"}