A tiny http client for iOS and macOS. Only 80 lines of code.
let request = HttpRequest(
url: "https://httpbin.org/get",
parameters: ["name": "Alex"],
)
request.json(HttpBin.self) { json, response in
print(json)
}
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)
}
}
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)
}
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)
}
HttpRequest(url: "https://httpbin.org/get").data() { data, response in
if let data {
let string = String(
data: data,
encoding: .utf8
)
print(string)
}
}
https://github.com/mezhevikin/http-request.git
pod 'HttpRequest', :git => 'https://github.com/mezhevikin/http-request.git'
๐ HttpRequest for Kotlin/Android
โ๏ธ Buy me a coffee