目录
目录README.md

HotSpring

apm Swift Package Manager Build Status

A simple http client interface for Swift. HotSpring also works on Linux.

Requirements

Swift

  • Swift 4.0.3

macOS

  • macOS Sierra 10.12.2

Linux

  • Ubuntu 14.04 Trusty(test passed)

Installation

Add the following to your dependencies in Package.swift.

Swift Package Manager v3

.Package(url: "https://github.com/rb-de0/HotSpring.git", majorVersion: 0)

Swift Package Manager v4

.package(url: "https://github.com/rb-de0/HotSpring.git", from: "0.3.0")

Usage

HotSpring is just a package that provides an interface for HTTP requests. HTTP clients are not implemented in HotSpring, but we implemented an HTTP client using Just as a sample. Therefore, you can use JustHTTPClient.

The following is a sample.

import HotSpring
import JustHTTPClient

enum SampleError: Error {
    case invalidResponse
}

struct SampleRequest: Request {
    
    let base = URL(string: "https://httpbin.org/get")!
    let path = ""
    let method = HTTPMethod.get
    
    func decodeResponse(_ data: Any) throws -> Data {
        
        guard let data = data as? Data else {
            throw SampleError.invalidResponse
        }
        
        return data
    }
}

let executor = Executor.Builder().addHTTPClient(JustHTTPClient()).build()
executor.execute(request) {
    print($0.value, $0.error)
}

License

HotSpring is released under the MIT License. See the LICENSE file for more info.

关于
48.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号