Based on AsyncHTTPClient.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler. It is in early development, but Graceful Networking does support its use on supported platforms.
Once you have your Swift package set up, adding Graceful Networking as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/OliverLetterer/GracefulNetworking.git", .upToNextMajor(from: "0.1.0"))
]
Graceful Networking is slightly inspired by github.com/Alamofire/Alamofire.
NN.shared.get("https://jsonplaceholder.typicode.com/posts").response { response, error in
debugPrint(response)
}
struct PostResponse: Codable {
var id: Int
var title: String
var body: String
var userId: String
}
let parameters: [String: NNWWWURLFormEncodable] = [
"title": "title",
"body": "body",
"userId": "5"
]
NN.shared.post("https://jsonplaceholder.typicode.com/posts", parameters: parameters).responseDecodable(of: PostResponse.self) { response, error in
debugPrint(response)
}
let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("image.png")
NN.shared.download("https://httpbin.org/image/png", destination: url) { respose, error in
debugPrint(respose)
}