Skip to content

muzle/SwiftNetworkApiRouter

Repository files navigation

ApiRouter

GitHub license codebeat badge

Library to simplify network routing management

Usage

import Foundation
import ApiRouter

internal enum WordRouter {
    case words(query: Encodable)
    case wordMeaning(query: Encodable)
}

// MARK: - Implement AbstractRouter

extension WordRouter: AbstractRouter {
    var path: String {
        switch self {
        case .words:
            return publicV1 + "/words/search"
        case .wordMeaning:
            return publicV1 + "/meanings"
        }
    }
    
    var method: HTTPMethod {
        .get
    }
    
    var queryParameters: Encodable? {
        switch self {
        case .wordMeaning(let query), .words(let query):
            return query
        }
    }
    
    var body: Encodable? {
        nil
    }
}
let request = try route.convertToURLRequest(with: JSONEncoder())
let url = try route.convertToURL(with: JSONEncoder())

Instalation

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
    pod 'ApiRouter'
end

Replace YOUR_TARGET_NAME and then, in the Podfile directory, type:

$ pod install

Authors

Eugene Rudakov - linkedin

About

A small library that helps build network requests.

Resources

License

Stars

Watchers

Forks

Packages

No packages published