Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rhysforyou/superhighway
As big a networking library as you'll need
https://github.com/rhysforyou/superhighway
combine ios macos networking spm swift swift-concurrency swift-package-manager tvos watchos
Last synced: 5 days ago
JSON representation
As big a networking library as you'll need
- Host: GitHub
- URL: https://github.com/rhysforyou/superhighway
- Owner: rhysforyou
- License: unlicense
- Created: 2019-09-22T04:29:27.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-07-17T00:50:58.000Z (over 1 year ago)
- Last Synced: 2024-12-17T04:07:38.281Z (7 days ago)
- Topics: combine, ios, macos, networking, spm, swift, swift-concurrency, swift-package-manager, tvos, watchos
- Language: Swift
- Homepage:
- Size: 94.7 KB
- Stars: 15
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Superhighway
[![Build & Test Swift Package](https://github.com/rhysforyou/Superhighway/actions/workflows/swift-package.yml/badge.svg?branch=main)](https://github.com/rhysforyou/Superhighway/actions/workflows/swift-package.yml)
![Swift Package Manager Recommended](https://img.shields.io/badge/SPM-recommended-blue?style=flat-square)
![Supports macOS, iOS, tvOS, watchOS, and Linux](https://img.shields.io/badge/platform-macOS%20|%20iOS%20|%20tvOS%20|%20watchOS%20|%20Linux-blue?style=flat-square)
[![Licensed under the Unlicense](https://img.shields.io/github/license/rhysforyou/Superhighway?color=blue&style=flat-square)](LICENSE)[Swift Package Index listing](https://swiftpackageindex.com/rhysforyou/Superhighway) • [Documentation](https://swiftpackageindex.com/rhysforyou/Superhighway/main/documentation/superhighway) • [Compatibility](https://swiftpackageindex.com/rhysforyou/Superhighway/builds)
Superhighway is a networking library heavily inspired by [tiny-networking](https://github.com/objcio/tiny-networking). It defines an `Endpoint` type which encapsulates the relationship between a `URLRequest` and the `Decodable` entity it represents.
## A Simple Example
```swift
struct Repository: Decodable {
let id: Int64
let name: String
}func getRepository(author: String, name: String) -> Endpoint {
return Endpoint(
decoding: Repository.self,
method: .get,
url: URL(string: "https://api.github.com/repos/\(author)/\(name)")!
)
}let endpoint = getRepository(author: "rhysforyou", name: "Superhighway")
```This simply gives us the description of an endpoint, to actually load it, we can pass it to a URLSession:
```swift
do {
let (repository, _) = try await URLSession.default.response(for: endpoint)
print("Repository: \(repository)")
} catch {
print("Error: \(error)")
}
```If the task is cancelled 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
// swift-tools-version:5.5
import PackageDescriptionlet package = Package(
// ...
dependencies: [
.package(url: "https://github.com/rhysforyou/Superhighway.git", "0.5.0"..<"0.6.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.