Home

Awesome

Booming

Carthage compatible CocoaPods Compatible CocoaPods Compatible CocoaPods Compatible Platform

Booming is a base network library for Swift. Developed for Swift 5, it aims to make use of the latest language features. The framework's ultimate goal is to enable easy networking that makes it easy to write well-maintainable code.

RxNetworks is a declarative and reactive networking library for Swift.

<font color=red>🧚. RxSwift + Moya + HandyJSON / Codable + Plugins.👒👒👒</font>


English | įŽ€äŊ“中文

This is a network api set of infrastructure based on Moya, also support responsive network with RxSwift.

Features

At the moment, the most important features of Booming can be summarized as follows:

Usages

How to use CODE_OF_CONDUCT.

SharedAPI.userInfo(name: "yangKJ").request(successed: { response in
    // do somthing..
}, failed: { error in
    print(error.localizedDescription)
})

or use async/await with swift 5.5

Task {
    do {
        let response = try await LoadingAPI.test2("666").requestAsync()
        let json = response.bpm.mappedJson
        // do somthing..
        let model = LoadingModel.deserialize(from: json, designatedPath: "data")
    } catch {
        block(error.localizedDescription)
    }
}

Plugins

CocoaPods Compatible CocoaPods Compatible CocoaPods Compatible

This module is mainly based on moya package network related plugins.

For ios platform:

If you want to use token plugin and auth plugin you can refer to the project use case.

🎷 Simple to use, implement the protocol method in the API protocol, and then add the plugin to it:

var plugins: APIPlugins {
    let cache = NetworkCachePlugin.init()
    let loading = NetworkLoadingPlugin.init()
    let warning = NetworkWarningPlugin.init()
    let shared = NetworkSharedPlugin.init()
    let gzip = NetworkGZipPlugin.init()
    return [loading, cache, warning, shared, gzip]
}

RxSwift

This module mainly supports responsive data binding.

func request(_ count: Int) -> Observable<[CacheModel]> {
    CacheAPI.cache(count).request()
        .deserialized(ApiResponse<[CacheModel]>.self)
        .compactMap { $0.data }
        .observe(on: MainScheduler.instance)
        .catchAndReturn([])
}

HollowCodable

HollowCodable is a codable customization using property wrappers library for Swift.

This module is serialize and deserialize the data, Replace HandyJSON.

🎷 Example of use in conjunction with the network part:

func request(_ count: Int) -> Observable<[LoadingModel]> {
    CodableAPI.cache(count)
        .request(callbackQueue: DispatchQueue(label: "request.codable"))
        .deserialized(ApiResponse<[LoadingModel]>.self)
        .compactMap({ $0.data })
        .observe(on: MainScheduler.instance)
        .catchAndReturn([])
}
<details> <summary>RxSwift deserialized extension.</summary>
public extension Observable where Element: Any {
    
    @discardableResult func deserialized<T>(_ type: T.Type) -> Observable<T> where T: HollowCodable {
        return self.map { element -> T in
            return try T.deserialize(element: element)
        }
    }
    
    @discardableResult func deserialized<T>(_ type: [T].Type) -> Observable<[T]> where T: HollowCodable {
        return self.map { element -> [T] in
            return try [T].deserialize(element: element)
        }
    }
    
    @discardableResult func deserialized<T>(_ type: T.Type) -> Observable<ApiResponse<T.DataType>> where T: HasResponsable, T.DataType: HollowCodable {
        return self.map { element -> ApiResponse<T.DataType> in
            return try T.deserialize(element: element)
        }
    }
    
    @discardableResult func deserialized<T>(_ type: T.Type) -> Observable<ApiResponse<[T.DataType.Element]>> where T: HasResponsable, T.DataType: Collection, T.DataType.Element: HollowCodable {
        return self.map { element -> ApiResponse<[T.DataType.Element]> in
            return try T.deserialize(element: element)
        }
    }
}
</details>

HandyJSON

⚠ī¸ Note: This module is not recommended because it has stopped maintenance.

<details> <summary>This module is based on HandyJSON package network data parsing.</summary>

🎷 Example of use in conjunction with the network part:

func request(_ count: Int) -> Driver<[CacheModel]> {
    CacheAPI.cache(count).request()
        .asObservable()
        .mapHandyJSON(HandyDataModel<[CacheModel]>.self)
        .compactMap { $0.data }
        .observe(on: MainScheduler.instance)
        .delay(.seconds(1), scheduler: MainScheduler.instance)
        .asDriver(onErrorJustReturn: [])
}
</details>

CocoaPods

CocoaPods is a dependency manager. For usage and installation instructions, visit their website. To integrate using CocoaPods, specify it in your Podfile:

pod 'Booming'

You should define your minimum deployment target explicitly, like:

platform :ios, '11.0'

If you want import cache plugin:

pod 'NetworkCachePlugin'

If you want import loading plugin:

pod 'NetworkHudsPlugin'

If you wang using Codable:

pod 'HollowCodable'

If responsive networking is required:

pod 'RxNetworks/RxSwift'

For other plugins and modules excluded, please read the podspec file.

Remarks

The general process is almost like this, the Demo is also written in great detail, you can check it out for yourself.🎷

BoomingDemo

Tip: If you find it helpful, please help me with a star. If you have any questions or needs, you can also issue.

Thanks.🎇

About the author

Buy me a coffee or support me on GitHub.

<a href="https://www.buymeacoffee.com/yangkj3102"> <img width=25% alt="yellow-button" src="https://user-images.githubusercontent.com/1888355/146226808-eb2e9ee0-c6bd-44a2-a330-3bbc8a6244cf.png"> </a>

Alipay or WeChat. Thanks.

<p align="left"> <img src="https://raw.githubusercontent.com/yangKJ/Harbeth/master/Screenshot/WechatIMG1.jpg" width=30% hspace="1px"> <img src="https://raw.githubusercontent.com/yangKJ/Harbeth/master/Screenshot/WechatIMG2.jpg" width=30% hspace="15px"> </p>

License

Booming is available under the MIT license. See the LICENSE file for more info.