Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.46 KB

README.md

File metadata and controls

67 lines (51 loc) · 1.46 KB

NetworkKit

I'm trying to do some an experiment to make a simple URLSession & URLSessionTask abstraction that intended to make a HTTP call so easy than before. Inspired by Moya

Usage

Just define the your request type that conforms to RequestProtocol

enum ProfileRequest {
    case profileByID(id: Int)
}

extension ProfileRequest: RequestProtocol {
    var baseURL: URL { 
        return URL(string: "http://yourapi.com")
    }

    var path: String {
        switch self {
        case .profileByID:
            return "/profile"
        }
    }

    var parameters: Parameters { 
        switch self {
        case .profileByID(let id):
            return ["id" : id]
        }
    }

    var headers: [String : String] { 
        return [:]
    }

    var parameterEncoder: ParameterEncoder { 
        switch self {
        case .profileByID:
            return URLParameterEncoder.defaultInstance
        }
    }

    var method: RequestMethod { 
        switch self {
        case .profileByID:
            return .get
        }
    }
}

Then make the provider & do some request!

let provider = NetworkProvider<ProfileRequest>()

provider.request(.profileByID(id: 1)) { result in 
    // handle your result
}

Installation

Currently manual yet, just add this project to your workspace & don't forget to link the NetworkKit.framework at your app build phase.

Feedbacks is appreciated, so we can learn together :D