Swiftpack.co -  rhysforyou/Superhighway as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
rhysforyou/Superhighway
A tiny networking library with Combine support
.package(url: "https://github.com/rhysforyou/Superhighway.git", from: "0.4.1")

Superhighway

Travis Build Status Swift Package Manager Recommended Supports macOS, iOS, tvOS, watchOS, and Linux Licensed under the Unlicense

Superhighway is a networking library heavily inspired by tiny-networking, but designed primarily for use with Combine. It defines an Endpoint type which encapsulates the relationship between a URLRequest and the Decodable entity it represents.

A Simple Example

struct Repository: Decodable {
    let id: Int64
    let name: String
}

func repository(author: String, name: String) -> Endpoint<Repository> {
    return Endpoint(json: .get, url: URL(string: "https://api.github.com/repos/\(author)/\(name)")!)
}

let endpoint = repository(author: "rhysforyou", name: "Superhighway")

This simply gives us the description of an endpoint, to actually load it, we need to subscribe to its publisher:

subscriber = URLSesion.shared.endpointPublisher(endpoint)
    .sink(receiveCompletion: { print("Completed: \($0)") },
          receiveValue: { print("Value: \($0)") })

If the subscriber is cancelled or deallocated before it finishes, any networking operations will be halted.

Installing

The recommended way to use Superhighway is through the Swift Package manager. For Xcode projects, simply add this repository to the project's Swift packages list. For projects using a Package.swift file, add the following:

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    // ...
    dependencies: [
        .package(url: "https://github.com/rhysforyou/Superhighway.git", "0.4.0"..<"0.5.0")
    ],
    targets: [
        .target(
            name: "MyTarget",
            dependencies: ["Superhighway"])
    ]
)

Other package managers such as CocoaPods and Carthage are officially unsupported, but this entire library is encapsulated in a single Endpoint.swift file which can be copied into an existing project and used as-is.

GitHub

link
Stars: 13
Last commit: 6 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

0.4.1
49 weeks ago

Changed

  • Project renamed from Porygon to Superhighway
  • Support for arbitrary MIME types for Accept and Content-Type headers using ContentType.custom
  • Support using a custom JSONEncoder when making requests with a JSON body

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