目录
目录README.md

HttpRequest

A tiny http client for iOS and macOS. Only 80 lines of code.

Get

let request = HttpRequest(
    url: "https://httpbin.org/get",
    parameters: ["name": "Alex"],
)
request.json(HttpBin.self) { json, response in
    print(json)
}

Post

let request = HttpRequest(
    url: "https://httpbin.org/post",
    method: .post,
    parameters: ["name": "Alex"],
    headers: ["User-Agent": "HttpRequest"]
)
request.json(HttpBin.self) { json, response in
    if let json {
         print(json)
    } else if let error = response.error {
        print(error)
    }
}

URLRequest and HTTPURLResponse

var request = HttpRequest(
    url: "https://httpbin.org/get",
)
request.timeoutInterval = 30
request.cachePolicy = .reloadIgnoringCacheData
request.json(HttpBin.self) { json, response in
    print(response.original.statusCode)
    print(response.original.allHeaderFields)
}

Json

struct HttpBin: Codable {
    let args: [String: String]?
    let form: [String: String]?
    let headers: [String: String]?
}

HttpRequest(url: "https://httpbin.org/get").json(HttpBin.self) { json, response in
    print(json)
}

Data and String

HttpRequest(url: "https://httpbin.org/get").data() { data, response in
    if let data {
        let string = String(
            data: data,
            encoding: .utf8
        )
        print(string)
    }
}

Swift Package Manager

https://github.com/mezhevikin/http-request.git

CocoaPods

pod 'HttpRequest', :git => 'https://github.com/mezhevikin/http-request.git'

🌐 HttpRequest for Kotlin/Android

💹 Best Currency Converter

☕️ Buy me a coffee

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

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