GracefulNetworking

main

HTTP Networking in Swift.
OliverLetterer/GracefulNetworking

Graceful Networking

Elegant Networking in Swift

Platforms Swift Swift Package Manager

Based on AsyncHTTPClient.

Swift Package Manager

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"))
]

Credit

Graceful Networking is slightly inspired by github.com/Alamofire/Alamofire.

Making requests

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)
}

Downloading data to a file

let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("image.png")
NN.shared.download("https://httpbin.org/image/png", destination: url) { respose, error in
    debugPrint(respose)
}

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

Last updated: Wed Nov 09 2022 00:48:33 GMT-0500 (GMT-05:00)