Swiftpack.co - achtungsoftware/NetworkKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by achtungsoftware.
achtungsoftware/NetworkKit 1.3.0
A high level Swift library for making HTTP requests.
⭐️ 2
🕓 1 year ago
.package(url: "https://github.com/achtungsoftware/NetworkKit.git", from: "1.3.0")

Swift Apache 2.0

NetworkKit

NetworkKit is a very high level api for http network requests and is used by Knoggl.

NetworkKit also handles json decoding for you.

Examples

Import

import NetworkKit

Async await

Replace post with get to make get requests instead.

// Post request
let (result, success) = try await NKHttp.post("YOUR_URL_STRING", parameters: ["foo": "bar"])

// Post request (json object model)
let obj: Model = try await NKHttp.postObject("YOUR_URL_STRING", parameters: ["foo": "bar"], type: Model.self)

// Post request (json object model array)
let array: Array<Model> = try await NKHttp.postObjectArray("YOUR_URL_STRING", parameters: ["foo": "bar"], type: Model.self)

With callback / completition

Replace post with get to make get requests instead.

// Post request
NKHttp.post("YOUR_URL_STRING", parameters: ["foo": "bar"]) { result, success in
    if success {
        print(result)
    }
}

// Post request (json object model)
NKHttp.postObject("YOUR_URL_STRING", parameters: ["foo": "bar"], type: Model.self) { object in
    if let object = object {
        // Do something with your object
    }
}

// Post request (json object model array)
NKHttp.postObjectArray("YOUR_URL_STRING", parameters: ["foo": "bar"], type: Model.self) { array in
    if let array = array {
        // Do something with your array
    }
}

Upload

The upload method allows you to upload multiple UIImages, video URLs and audio URLs.

// Callback
NKHttp.upload("YOUR_URL_STRING", parameters: ["foo": "bar"],
videos: [String: URL], 
images: [String: UIImage], 
audios: [String: URL]) { result, success in
    if success {
        print(result)
    }
}

// Async await
let (result, success) = await NKHttp.upload("YOUR_URL_STRING", parameters: ["foo": "bar"],
videos: [String: URL], 
images: [String: UIImage], 
audios: [String: URL])

if success {
    print(result)
}

GitHub

link
Stars: 2
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.3.0
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics