Swiftpack.co - hooliooo/Astral as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by hooliooo.
hooliooo/Astral 3.0.0
An HTTP networking library that emphasizes ease of use and ergonomics. Based on Rust's reqwest library
⭐️ 0
🕓 2 years ago
iOS macOS
.package(url: "https://github.com/hooliooo/Astral.git", from: "3.0.0")

Astral

Astral is a minimal HTTP Networking library that aims to simplify an application's networking layer by abstracting the steps needed to create a network request into an easy to use API. Astral uses Swift's async/await concurrency features.

Requirements

Astral requires Swift 5.6

Installation

CocoaPods

  1. Add the following to your Podfile:
pod 'Astral'
  1. Integrate your dependencies using frameworks: add use_frameworks! to your Podfile.
  2. Run pod install.

Carthage

Add the following to your Cartfile:

github "hooliooo/Astral"

Swift Package Manager

Add the following dependency in your Package.swift file:

.package(url: "https://github.com/hooliooo/Astral.git", from: "3.0.0")

A Simple Example

Here's an example using the Pokemon API

class PokemonAPIClient {

    let client: Client = Client()
    private let baseURL: String = "https://pokeapi.co/api/v2"

    func getPokemon(id: Int) async throws -> (Pokemon, URLResponse) {
        return try await client
            .get("\(self.baseURL)/pokemon/\(id)")
            .headers(
                headers: [
                    Header(key: Header.Key.accept, value: Header.Value.mediaType(.applicationJSON)),
                ]
            )
            .send()
    }

}

Author

Julio Alorro

License

Astral is available under the MIT license. See the LICENSE file for more info.

GitHub

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

Related Packages

Release Notes

6 years ago

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