arrow-left

Only this pageAll pages
gitbookPowered by GitBook
1 of 16

Swift Cloud

Loading...

Platform

Loading...

Loading...

Loading...

Loading...

Console

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Welcome

Fast. Secure. Server Side Swift.

In 2022 developers expect a lot from platforms out of the box. Things like 1 click deploys, deploy to URL, connecting to GitHub, etc. Platforms like Heroku, Netlify, Vercel and more, have spoiled us with developer friendly features to deploy code to the cloud and make it instantly available. But these platforms almost all specialize in Javascript and front-end development. We built Swift Cloud to bring these feature sets to developers looking to build backend applications and websites in the Swift language.

Swift 5.5 introduced Concurrency - async/await, structured concurrency, Actors, etc. greatly simplifying what it takes to write performant, safe, server side Swift code. Since the introduction of these features, many people have found Swift to be an excellent language for building server side applications, including Apple. Apple has made a strong push to make Swift fully available on Linux, and even built projects like the Swift AWS Lambda runtime. But even with the great support coming from Apple, depoloying server side Swift still takes a lot of operational expertise, and then even once deployed developers are missing those platform features that we have come to expect.

Swift Cloud aims to solve this problem by providing a platform that gives developers a robust set of features for deploying Swift to the cloud. Things like 1 click deploys, HTTP/3, globally distributed, 100ms cold starts, custom domains and more.

Respond to Requests

Responding to HTTP requests is just as simple as listening for them, simply call the various send() methods on the OutgoingResponse object:

import Compute

@main
struct HelloCompute {
    static func main() async throws {
        try await onIncomingRequest(handleIncomingRequest)
    }

    static func handleIncomingRequest(req: IncomingRequest, res: OutgoingResponse) async throws {
        let text = "Hello, World."
        try await res.status(200).send(text)
    }
}

The Compute library provides various versions of send that allow you to pass JSON data, Encodable's, HTML, XML and raw bytes / streams of data.

Web Assembly

Compile your Swift applications to web assembly

Swift Cloud is made possible by the incredible SwiftWasmarrow-up-right project, but probably not in the way you might think. Web Assembly is making waves as being a new high performance environment for web application development but its also powering cloud computing platforms like Cloudflare Workers and Fastly Compute@Edge. Swift Cloud works by compiling your code to Web Assembly and deploying it to the Fastly Compute@Edge platform. Swift Cloud builds your code and manages Fastly compute services behind the scenes so you do not need a Fastly account or any existing knowledge about how the Fastly platform works.

hashtag
Limitations

There's no two ways about it - Swift Cloud has serious limitations that will take some getting used to. First of all, it's important to understand that these limitations exist today because of the platform we chose to build on first. We have plans to introduce other deployment targets (like AWS Lambda) that remove some limitations and introduce others. We chose to build on the Fastly platform as we believe it provides the absolute best HTTP stack available today. Starting with HTTP allows us to focus on the primary way we think iOS developers and macOS developers will use the platform when getting started. We're thinking basic integrations with Stripe, Slack, Twilio etc. all of which will require an HTTP backend for your apps.

hashtag
Swift Foundation and Dispatch

is available in SwiftWasm, but in a limited capacity. The main reason is that is unavailable due to in WebAssembly and SwiftWasm itself. Many Foundation APIs rely on the presence of Dispatch under the hood, specifically file system access and threading helpers. A few other types are unavailable in browsers or aren't standardized in WASI hosts, such as support for sockets and low-level networking, or support for time zone files, and they had to be disabled. These types are therefore absent in SwiftWasm Foundation:

  • FoundationNetworking types, such as URLSession and related APIs

  • FileManager

Related functions and properties on other types are also absent or disabled. We would like to make them available in the future as soon as possible, and and help us in achieving this goal.

Host
  • Notification

  • NotificationQueue

  • NSKeyedArchiver

  • NSKeyedArchiverHelpers

  • NSKeyedCoderOldStyleArray

  • NSKeyedUnarchiver

  • NSNotification

  • NSSpecialValue

  • Port

  • PortMessage

  • Process

  • ProcessInfo (Partially available since 5.7)

  • PropertyListEncoder

  • RunLoop

  • Stream

  • Thread

  • Timer

  • UserDefaults

  • The Foundation core libraryarrow-up-right
    the Dispatch core libraryarrow-up-right
    the lack of standardized multi-threading supportarrow-up-right
    we invite you to contributearrow-up-right

    Domains

    Connect custom domains

    Compute Runtime

    The core library for building apps on Swift Cloud

    To get started building apps on Swift Cloud, you must install the [Swift Compute Runtime](https://github.com/AndrewBarba/swift-compute-runtimearrow-up-right) using Swift Package Manager:

    .package(url: "https://github.com/AndrewBarba/swift-compute-runtime", from: "1.0.0")

    The compute runtime provides bindings to the underlying WASM runtime giving you the ability to listen for HTTP requests, make outgoing HTTP requests, read dictionary and environment variables, and a whole lot more.

    The library was designed with modern Swift features like async/await to make concurrent programing as easy and safe to use as possible. It also provides lower level abstractions for working directly with streaming data, giving developers the highest level of flexibility when working building their API's. One main advantage of building on the Fastly platform is the superior HTTP stack compared to other serverless platforms like AWS Lambda. Lambda does not have any ability to stream responses to clients and thus limits what you can do with binary data like images and MP3's. On Swift Cloud you have full control over streaming requests and responses.

    Listen for Requests

    All Swift Cloud applications start with listening for an incoming HTTP request. This is accomplished by calling onIncomingRequest in your main handler function:

    import Compute
    
    @main
    struct App {
        static func main() async throws {
            try await onIncomingRequest(handleIncomingRequest)
        }
    
        static func handleIncomingRequest(req: IncomingRequest, res: OutgoingResponse) async throws {
            print("Handling request:", req.url.pathname)
        }
    }

    Metrics

    Dictionaries

    Origins

    Fetch data in your application

    Logs

    Projects

    Connect your code to Swift Cloud

    Deployments

    Deploy your code to Swift Cloud

    Teams

    Plans & Billing