Skip to content

paylike/swift-request

Repository files navigation

PaylikeRequest - Paylike low-level request helper

build_test

Request implementation for Swift

This implementation is based on Paylike/JS-Request

Install

SPM:

// dependencies: 
.package(url: "[email protected]:paylike/swift-request.git", .upToNextMajor(from: "0.3.0"))

// target:
.product(name: "PaylikeRequest", package: "swift-request")

Cocoapods: https://cocoapods.org/pods/PaylikeRequest

pod 'PaylikeRequest'

Usage

import PaylikeRequest

// ...

// optionally logging function can be overwritten
let httpClient = PaylikeHTTPClient(log: { item in
    print(item) // Item is encodable
})

let options = RequestOptions(
    withData: ["foo": "bar"]
)

// completion handler version
httpClient.sendRequest(
    to: URL(string: "http://localhost:8080/bar")!,
    withOptions: options
) { result in
    // handle result in callback style
}

// Async version
Task {
    let response = try await httpClient.sendRequest(
        to: URL(string: "http://localhost:8080/bar")!,
        withOptions: options
    )
}

// A more simple usage with options default parameters:

// ...

Task {
    let response = try await httpClient.sendRequest(
        to: URL(string: "http://localhost:8080/bar")!
    )
}

About

Request implementation for Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published