Coder Social home page Coder Social logo

superhighway's Introduction

Superhighway

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

Swift Package Index listingDocumentationCompatibility

Superhighway is a networking library heavily inspired by tiny-networking. 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 getRepository(author: String, name: String) -> Endpoint<Repository> {
  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:

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-tools-version:5.5
import PackageDescription

let 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.

superhighway's People

Contributors

rhysforyou avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.