Swiftpack.co - JustinGuedes/swervice as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by JustinGuedes.
JustinGuedes/swervice 0.0.3
A simple networking library for swift
⭐️ 4
🕓 44 weeks ago
iOS macOS
.package(url: "https://github.com/JustinGuedes/swervice.git", from: "0.0.3")

Swervice

A simple networking library for swift.

Usage

The easiest way to fire off a service call is by using the ServiceHelper. For a more customised way of firing off service calls check the URLRequestBuilder section.

ServiceHelper

Define your service class/struct and ensure it conforms to ServiceHelper:

struct ExampleService: ServiceHelper {
    
    // 1. Implement the config for the service you want to speak to
    var config: ServiceHelperConfig = .init(
        host: "example.com", // The host of the service
        authorization: .basic("username", "password) // The authorization for the service
    )
    
}

Once you have conformed to ServiceHelper you can implement your service specific methods:

struct ExampleService: ServiceHelper {
    
    // ...
    
    /// Fires off a GET request to https://example.com/api and returns
    /// a Response object provided no errors occur.
    func getTest() async throws -> Response {
        return try await get(from: "/api")
    }
    
}

URLRequestBuilder

Description coming soon.

License

Swervice is released under the MIT license. See LICENSE for details.

GitHub

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

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