Entryable

master

yume190/Entryable

Entryable


SPM

.package(url: "https://github.com/yume190/Entryable.git", from: "5.1.0")

Pod

pod 'YumeAlamofire', :git => 'https://github.com/yume190/Entryable.git', :tag => '5.1.0'


Example

struct Entry {
    static let base = "http://127.0.0.1:3000"
    
    public static let session: Session = {
        let configuration = URLSessionConfiguration.default
        configuration.timeoutIntervalForRequest = 15 // seconds
        configuration.timeoutIntervalForResource = 15
        configuration.urlCache = nil
        return Session(configuration: configuration, requestQueue: DispatchQueue.global(qos: .background))
//        return Session(configuration: configuration)
    }()
}

extension Entry {
    struct A: EncodeEntryable {
        typealias ResponseType = Response
        
        public struct Parameters: Encodable {
            let a: String
        }
        
        let key: String
        
        let url: URLConvertible = Entry.base + "/yume"
        let session: Session = Entry.session
        let method: Alamofire.HTTPMethod = .get
        let parameters: Parameters? = Parameters(a: "b")
        let parameterType: ParameterType = .url
        var headers: Headers {
            return ["key" : key]
        }
    }
}

extension Entry.A {
    public struct Response: Codable, Equatable {
        let code: Int
        let message: String
    }
}

extension Entry {
    struct B: DictionaryEntryable {
        typealias ResponseType = Void
        
        let key: String
        init(key: String) {
            self.key = key
        }
        
        let url: URLConvertible = Entry.base + "/yume"
        let session: Session = Entry.session
        let method: Alamofire.HTTPMethod = .head
        let parameters: Parameters? = [:]
        var headers: Headers {
            return ["key" : key]
        }
    }
}

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Mon Oct 21 2024 13:49:21 GMT-0900 (Hawaii-Aleutian Daylight Time)