GSNetwork 1.0.0

GSNetwork 1.0.0

Maintained by Gloomy Meng.



 
Depends on:
GSBasis>= 0
Alamofire~> 5.0.0-beta.5
 

GSNetwork 1.0.0

GSNetwork

CI Status Version License Platform

Features

  • Category, SPM installation
  • OAuth interceptor
  • etc..

Usage

A simple network components, simple and clear API usage with only two files.

Support diverse data structure returns while guaranteeing type checking.

Unified error types and standard error handling.

Dependent on Alamofire

Define API list

First, initialized GSNetwork with a GSNetworkConfig

Network.config(config: GSNetworkConfig.init().then {
    $0.host = ""
    $0.customHeader = [:]
    //..//
})

Seconds, for different module need define different APIRoute

enum UserRoute: APIRoute {
    
    case userInfo(id: String)
    case upateInfo(user: User)
    case logout
    case login(username: String, password: String)
    
    var uri: String {
        switch self {
        case .userInfo(let id):                     return ""
        case .upateInfo(let user):                  return ""
        case .logout:                               return ""
        case .login(let username, let password):    return ""
        }
    }
    
    var parameters: [String : Any] { return [:] }
    
    var method: HTTPMethod {
        switch self {
        case .userInfo(let id):                     return .get
        case .upateInfo(let user):                  return .post
        case .logout:                               return .get
        case .login(let username, let password):    return .get
        }
    }
    
    var encodeType: HTTPEncodeType { return .json }
    
    func customHost() -> String? { return nil }
}

Lastly, start requst like this

UserRoute.logout.start(success: { (rs: APIReturn<Bool>) in
    // do something...
})

Requirements

  • iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
  • Xcode 10.2+
  • Swift 5+

Installation

Cocoapods

GSNetwork is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'GSNetwork'

Author

[email protected], [email protected]

License

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