{"id":1657,"url":"https://github.com/mmoaay/Bamboots","last_synced_at":"2025-08-02T04:32:22.459Z","repository":{"id":56502663,"uuid":"62683997","full_name":"mmoaay/Bamboots","owner":"mmoaay","description":"Bamboots - Extension 4 Alamofire","archived":false,"fork":false,"pushed_at":"2020-11-03T17:26:38.000Z","size":29442,"stargazers_count":439,"open_issues_count":6,"forks_count":39,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-08-02T00:13:38.875Z","etag":null,"topics":["alamofire","alamofire-extension","chained-calls","codable","loading","networking","protocol-oriented","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/mmoaay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-06T02:15:01.000Z","updated_at":"2025-07-08T02:17:28.000Z","dependencies_parsed_at":"2022-08-15T20:00:30.520Z","dependency_job_id":null,"html_url":"https://github.com/mmoaay/Bamboots","commit_stats":null,"previous_names":["mmoaay/mbnetwork"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/mmoaay/Bamboots","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoaay%2FBamboots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoaay%2FBamboots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoaay%2FBamboots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoaay%2FBamboots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmoaay","download_url":"https://codeload.github.com/mmoaay/Bamboots/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmoaay%2FBamboots/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334615,"owners_count":24233793,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["alamofire","alamofire-extension","chained-calls","codable","loading","networking","protocol-oriented","swift"],"created_at":"2024-01-05T20:15:52.484Z","updated_at":"2025-08-02T04:32:21.946Z","avatar_url":"https://github.com/mmoaay.png","language":"Swift","funding_links":[],"categories":["Networking"],"sub_categories":["Video","Other free courses"],"readme":"![Bamboots: Extension 4 Alamofire](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_banner.png)\n\n[![CI Status](http://img.shields.io/travis/mmoaay/Bamboots.svg?style=flat)](https://travis-ci.org/mmoaay/Bamboots)\n[![Version](https://img.shields.io/cocoapods/v/Bamboots.svg?style=flat)](http://cocoapods.org/pods/Bamboots)\n[![Platform](https://img.shields.io/cocoapods/p/Bamboots.svg?style=flat)](http://cocoapods.org/pods/Bamboots)\n[![Language](https://img.shields.io/badge/language-swift-orange.svg)](https://github.com/apple/swift)\n[![Codebeat](https://codebeat.co/badges/571ff02f-8f09-4960-b0e4-d4c6210251cf)](https://codebeat.co/projects/github-com-mmoaay-bamboots-master)\n[![License](https://img.shields.io/cocoapods/l/Bamboots.svg?style=flat)](http://cocoapods.org/pods/Bamboots)\n[![Gitter](https://img.shields.io/gitter/room/Bamboots/Bamboots.svg)](https://gitter.im/Bamboots-Gitter/Lobby)\n[![Weibo](https://img.shields.io/badge/weibo-@mmoaay-red.svg?style=flat)](https://weibo.com/smmoaay)\n![\\\u003c3](https://img.shields.io/badge/made%20with-%3C3-orange.svg)\n\n**Bamboots** is a network request framework based on [Alamofire](https://github.com/Alamofire/Alamofire) , aiming at making network request easier for business development.\n\n- [Protocols](#protocols)\n- [Features](#features)\n- [Requirements](#requirements)\n- [Usage](#usage)\n- [Chained calls](#chained-calls)\n- [Bonus](#bonus)\n- [Example](#example)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Author](#author)\n- [License](#license)\n\n## Protocols\n\n**Bamboots** has made advantages of protocol-oriented programming and abstracted everything that relevant to network request into protocol. Here is the protocol list: \n\n - `Requestable`: Network request protocol, object conforms to this protocol can make network request.\n - `Formable`: Form protocol. Object conforms to this protocol can be used by the `request`, `download`, `upload` method in `Requestable` protocol.\n   - `UploadFormable`: Upload Form protocol, Base protocol for upload request form.\n     - `UploadStreamFormable`: Conforming to this protocol to create an upload form that contains a stream object.\n     - `UploadDataFormable`: Conforming to this protocol to create an upload form that contains a data object.\n     - `UploadFileFormable`: Conforming to this protocol to create an upload form that contains a file.\n     - `UploadMultiFormDataFormable`: Conforming to this protocol to create an upload form that contains multiformdata.\n   - `DownloadFormable`: Download Form protocol, Base protocol for download request form.\n     - `DownloadResumeFormable`: Conforming to this protocol to create a download form that can resume a download task.\n   - `RequestFormable`: Conforming to this protocol to create a request form.\n - `Loadable`: Protocol used for showing mask on specified container when requesting (such as add `UIActivityIndicatorView` on `UIViewcontroller`'s view when request begins, and remove it when request ends). Object conforms to this protocol can be used by `load` method of `DataRequest`.\n   - `Maskable`: Mask protocol for `Loadable`, View that conforms to this protocol will be treated as mask.\n   - `Containable`: Container protocol for `Loadable`, Objects conforms to this protocol can be used as container for the mask.\n   - `Progressable`: Progress protocol for request, Objects conforms to this protocol can get the progress of the request. Object conforms to this protocol can be used by `progress` method of `DataRequest`.\n - `Messageable`: Message protocol.\n   - `Warnable`: Warn protocol. Conforming to this protocol to customize the way of warning messages displayed when error occured.\n   - `Informable`: Inform protocol. Conforming to this protocol to customize the way of inform messages displayed when request done successfully\n - `Errorable`: Error protocol. Conforming to this protocol to customize the error configuration.\n   - `JSONErrorable`: Error protocol for JSON data. Conforming to this protocol to customize the error configuration for JSON data.\n\nMostly you don't need to care much about these protocols, because we already have many **DEFAULT** implementations for them. However if you want to customize something, you just need to conform to these protocols and do what you want. Here is some default implementations for these protcols:\n\n- `LoadType`: Enum that conforms to `Loadable` protocol, using `case default(container:Containable)` case to show `MaskView` on the container when requesting.\n- `UIAlertController+Messageable`: With this extension, you can pass a UIAlertController directly into the `warn` and `inform` method of `DataRequest`. \n- `UIButton+Loadable`: With this extension, you can pass a button directly into the `load` method of `DataRequest`. \n- `UITableViewCell+Loadable`: With this extension, you can pass a cell directly into the `load` method of `DataRequest`.\n- `UIRefreshControl+Loadable`: With this extension, you can pass a UIRefreshControl directly into the `load` method of `DataRequest`.\n- `UIProgressView+Progressable`: With this extension, you can pass a UIProgressView directly into the `progress` method of `DataRequest`.\n- `UIScrollView+Containable`: Extending UIScrollView to conform to `Containable` protocol.\n- `UITableViewCell+Containable`: Extending UITableViewCell to conform to `Containable` protocol.\n- `UIViewController+Containable`: Extending UIViewController to conform to `Containable` protocol.\n- `ActivityIndicator`: Default mask for UITableViewCell and UIButton\n- `MaskView`: Default mask for others.\n\n## Features\n\n 1. There is no need to inherit any object to get the features it has, and you can extend any features you want without changing the code of **Bamboots** itself.\n 2. We have **Default** extension for most of the protocol, so you can easily startup.\n 3. And if you have special needs, extend or conform to it.\n 4. The API was designed with the principles of Alamofire, So you can also extend it as **Bamboots** already have done for you.\n 5. Mainly focus on things between business development and Alamofire, not network request itself.\n\n## Requirements\n\n - [Alamofire](https://github.com/Alamofire/Alamofire): Elegant HTTP Networking in Swift\n - [AlamofireCodable](https://github.com/CNKCQ/AlamofireCodable): An Alamofire extension which converts JSON response data into swift objects using Codable\n\n## Usage\n\n### Create a form\n\nFor business development, most of the requests' headers are the same, so you can extend it only for once.\n\n``` swift\nextension Formable {\n    public func headers() -\u003e [String: String] {\n        return [\"accessToken\":\"xxx\"];\n    }\n}\n\n```\nAnd you can also have extension for specified protocol\n\n``` swift\n\nextension Formable where Self: UploadFormable {\n    public func headers() -\u003e [String: String] {\n        return [\"accessToken\":\"xxx\", \"file\":\"xxx\"];\n    }\n}\n```\n\nAnd for other parameters such as `url`, `method`, `parameters` etc. \nEach request will has it's own value, So we create an object and make it conforms to the protocol\n\n``` swift\nstruct WeatherForm: RequestFormable {\n    var city = \"shanghai\"\n    \n    public func parameters() -\u003e [String: Any] {\n        return [\"city\": city]\n    }\n\n    var url = \"https://raw.githubusercontent.com/tristanhimmelman/AlamofireObjectMapper/2ee8f34d21e8febfdefb2b3a403f18a43818d70a/sample_keypath_json\"\n    var method = Alamofire.HTTPMethod.get\n}\n```\n\n### Make a request\n\nAll you have to do is conforming to `Requestable` protocol, in this protocol, we've already implement some methods for you: \n\n- `func request(_ form: RequestFormable) -\u003e DataRequest`\n- `func download(_ form: DownloadFormable) -\u003e DownloadRequest`\n- `func download(_ form: DownloadResumeFormable) -\u003e DownloadRequest`\n- `func upload(_ form: UploadDataFormable) -\u003e UploadRequest`\n- `func upload(_ form: UploadFileFormable) -\u003e UploadRequest`\n- `func upload(_ form: UploadStreamFormable) -\u003e UploadRequest`\n- `func upload(_ form: UploadMultiFormDataFormable, completion: ((UploadRequest) -\u003e Void)?)`\n\nHere is the usage of request method: \n\n``` swift\nclass LoadableViewController: UIViewController, Requestable {\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        // Do any additional setup after loading the view.\n        request(WeatherForm())\n    }\n}\n```\n\n### Show mask when requesting\n\nWe have extended `DataRequest` class of Alamofire and added a `load` method to it.\n\n``` swift\nfunc load(load: Loadable = LoadType.none) -\u003e Self\n```\n\n#### Show mask on `UIViewController`\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_loadable_uiviewcontroller.gif)\n\n``` swift\nrequest(WeatherForm()).load(load: LoadType.default(container: self))\n```\n\n#### Show mask on `UIButton`\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_loadable_button.gif)\n\n``` swift\nrequest(WeatherForm()).load(load: button)\n```\n\n\u003e **Notice**: The color of `UIActivityIndicatorView` is the `tintColor` of `UIButton `\n\n#### Show customized mask\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_loadable_customized.gif)\n\nFirstly, we create a `LoadConfig` class conforms to `Loadable` protocol.\n\n``` swift\nclass LoadConfig: Loadable {\n    init(container: Containable? = nil, mask: Maskable? = MaskView(), inset: UIEdgeInsets = UIEdgeInsets.zero) {\n        insetMine = inset\n        maskMine = mask\n        containerMine = container\n    }\n    \n    func mask() -\u003e Maskable? {\n        return maskMine\n    }\n    \n    func inset() -\u003e UIEdgeInsets {\n        return insetMine\n    }\n    \n    func maskContainer() -\u003e Containable? {\n        return containerMine\n    }\n    \n    func begin() {\n        show()\n    }\n    \n    func end() {\n        hide()\n    }\n    \n    var insetMine: UIEdgeInsets\n    var maskMine: Maskable?\n    var containerMine: Containable?\n}\n```\n\nThen we can use it as followed:\n\n\n``` swift\nlet load = LoadConfig(container: view, mask:EyeLoading(), inset: UIEdgeInsetsMake(30+64, 15, UIScreen.main.bounds.height-64-(44*4+30+15*3), 15))\nrequest(WeatherForm()).load(load: load)\n```\n\nThis is the most powerful usage of the `Loadable` protocol. In this way you can customized everything the `Loadable` protocol has.\n\n#### Show mask on `UITableView` \u0026 `UIScrollView`\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_loadable_uiscrollview.gif)\n\n``` swift\n\nlet load = LoadConfig(container:self.tableView, mask: ActivityIndicator(), inset: UIEdgeInsetsMake(UIScreen.main.bounds.width - self.tableView.contentOffset.y \u003e 0 ? UIScreen.main.bounds.width - self.tableView.contentOffset.y : 0, 0, 0, 0))\nrequest(WeatherForm()).load(load: load)\n        \n```\n\n#### Show mask on `UITableViewCell` (PS: Still in development)\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_loadable_cell.gif)\n\n``` swift\nrefresh.attributedTitle = NSAttributedString(string: \"Loadable UIRefreshControl\")\nrefresh.addTarget(self, action: #selector(LoadableTableViewController.refresh(refresh:)), for: .valueChanged)\ntableView.addSubview(refresh)\n     \nfunc refresh(refresh: UIRefreshControl) {\n    request(WeatherForm()).load(load: refresh)\n}\n```\n\n### Loadable `UIRefreshControl`\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_loadable_refresh.gif)\n\n``` swift\noverride func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {\n    tableView .deselectRow(at: indexPath, animated: false)\n    let cell = tableView.cellForRow(at: indexPath)\n    request(WeatherForm()).load(load: cell!)\n}\n```\n\nWe can also support other refresh control such as `MJRefresh`.\n\n### Show progress when requesting\n\nWe have extended `DownloadRequest` and `UploadRequest` class of Alamofire and added a `progress` method to it.\n\n``` swift\nfunc progress(progress: Progressable) -\u003e Self\n```\n\nAnd then we can use it as followed:\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_progressable.gif)\n\n``` swift\ndownload(ImageDownloadForm()).progress(progress: progress)\n```\n\n### Show warning message if fail\n\nWe have extended `DataRequest` class of Alamofire and added a `warn` method to it.\n\n``` swift\nfunc warn\u003cT: JSONErrorable\u003e(error: T, warn: Warnable, completionHandler: ((JSONErrorable) -\u003e Void)? = nil) -\u003e Self\n```\n\nAnd then we can use it as followed:\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_warnable.gif)\n\n``` swift\nlet alert = UIAlertController(title: \"Warning\", message: \"Network unavailable\", preferredStyle: .alert)\nalert.addAction(UIAlertAction(title: \"Ok\", style: UIAlertActionStyle.cancel, handler: nil))\n        \nrequest(WeatherForm()).warn(\n    error: WeatherError(),\n    warn: alert\n)\n```\n\n\u003e **Notice**: We only have `warn` for JSON format response now.\n\n### Show inform message if success\n\nWe have extended `DataRequest` class of Alamofire and added a `inform` method to it.\n\n``` swift\nfunc inform\u003cT: JSONErrorable\u003e(error: T, inform: Informable) -\u003e Self\n```\n\nAnd then we can use it as followed:\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/bamboots_informable.gif)\n\n``` swift\nlet alert = UIAlertController(title: \"Notice\", message: \"Load successfully\", preferredStyle: .alert)\nalert.addAction(UIAlertAction(title: \"Ok\", style: UIAlertActionStyle.cancel, handler: nil))\nrequest(WeatherForm()).inform(\n    error: WeatherInformError(),\n    inform: alert\n)\n```\n\n\u003e **Notice**: We only have `inform ` for JSON format response now.\n\n### JSON to Object\n\n```swift\nrequest(WeatherForm()).responseObject(keyPath: \"data\") { (response: DataResponse\u003cWeatherResponse\u003e) in\n    if let value = response.result.value {\n        self.weatherResponse = value\n        self.tableView.reloadData()\n    }\n}\n\n```\n\nFor more information, see [AlamofireCodable](https://github.com/CNKCQ/AlamofireCodable).\n\n## Chained calls\n\nAll the method mentioned above can be called in a chained manner, such as followed:\n\n```swift\nlet load = LoadConfig(container: view, mask:EyeLoading(), inset: UIEdgeInsetsMake(30+64, 15, UIScreen.main.bounds.height-64-(44*4+30+15*3), 15))\n\nlet warn = UIAlertController(title: \"Warning\", message: \"Network unavailable\", preferredStyle: .alert)\nwarn.addAction(UIAlertAction(title: \"Ok\", style: UIAlertActionStyle.cancel, handler: nil))\n\nlet inform = UIAlertController(title: \"Notice\", message: \"Load successfully\", preferredStyle: .alert)\ninform.addAction(UIAlertAction(title: \"Ok\", style: UIAlertActionStyle.cancel, handler: nil))\n\nrequest(WeatherForm()).load(load:load).progress(progress: progress).warn(error: WeatherError(), warn: warn).inform(error: WeatherInformError(), inform: inform)\n```\n\n## Bonus\n\n### `Eyeloading`\n\n![](https://github.com/mmoaay/Bamboots/blob/master/Demo/EyeLoading.gif)\n\nWe've written this motion effect when implementing the customized loading, and it's all implemented with `CAAnimationGroup`.\n\nIf interested, you can check the file `Eyeloading` in example project.\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Installation\n\nBamboots is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'Bamboots'\n```\n\n## Protobuf Support\n```ruby\npod 'Bamboots/BambootsProtobuf'\n```\n* Use [apple/swift-protobuf](https://github.com/apple/swift-protobuf) as protobuf data deserialization\n* run protobuf test\n    * fist run `Example/Protobuf/pbdemo`\n    * open `Example/Bamboots.xcworkspace`\n    * run `command + u`\n\n## Author\n\nmmoaay, mm@swift.gg\n\n## License\n\n![](https://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/License_icon-mit-88x31-2.svg/128px-License_icon-mit-88x31-2.svg.png)\n\nBamboots is available under the MIT license. See the LICENSE file for more info.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmoaay%2FBamboots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmoaay%2FBamboots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmoaay%2FBamboots/lists"}