Swiftpack.co - Apodini/ApodiniAsyncHTTPClient as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Apodini.
Apodini/ApodiniAsyncHTTPClient 0.3.4
An Apodini extension to support the AsyncHTTPClient
⭐️ 0
🕓 2 years ago
macOS
.package(url: "https://github.com/Apodini/ApodiniAsyncHTTPClient.git", from: "0.3.4")

ApodiniAsyncHTTPClient

DOI codecov jazzy Build and Test

ApodiniAsyncHTTPClient extends Apodini with support for the AsyncHTTPClient to make HTTP requests in Handlers using the Environment: @Environment(\.httpClient) var httpClient: HTTPClient.
For more information about the AsyncHTTPClient check out the documentation fround in the AsyncHTTPClient repository at https://github.com/swift-server/async-http-client.

Requirements

ApodiniAsyncHTTPClient extends Apodini and can be added as an additional dependency to your Swift Package manifest (Package.swift):

dependencies: [
    .package(url: "https://github.com/Apodini/ApodiniAsyncHTTPClient.git", from: "0.1.0"),
    // And more Swift Package dependencies ...
],

You can use the dependency in your Apodini target as follows:

.target(
    name: "MyApodiniWebService",
    dependencies: [
        .product(name: "Apodini", package: "Apodini"),
        .product(name: "ApodiniAsyncHTTPClient", package: "ApodiniAsyncHTTPClient"),
        // And more dependencies for the target ...
    ]
),

Usage

You can use the AsyncHTTPClient to make HTTP requests in Handlers using the Environment: @Environment(\.httpClient) var httpClient: HTTPClient:

import Apodini
import ApodiniAsyncHTTPClient


struct CreateContact: Handler {
    @Environment(\.httpClient)
    var httpClient: HTTPClient
    
    
    func handle() throws -> EventLoopFuture<String> {
        httpClient
            .get(url: "https://github.com/Apodini/ApodiniAsyncHTTPClient")
            .map { response in
                guard response.status == .ok else {
                    return "❌"
                }
                return "ApodiniAsyncHTTPClient 🚀"
            }
    }
}

For more information about the AsyncHTTPClient check out the documentation fround in the AsyncHTTPClient repository at https://github.com/swift-server/async-http-client.

Contributing

Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first

License

This project is licensed under the MIT License. See License for more information.

GitHub

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

Release Notes

0.3.4
2 years ago

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