What's New

0.1.2

2022-09-01T05:36:45Z

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'

Links

🌐 HttpRequest for Kotlin/Android

💹 Best Currency Converter

☕️ Buy me a coffee

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Oct 17 2024 17:53:15 GMT-0900 (Hawaii-Aleutian Daylight Time)