Only this pageAll pages
Powered 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.

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)
    }
}

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.

Compute Runtime

The core library for building apps on Swift Cloud

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

To get started building apps on Swift Cloud, you must install the [Swift Compute Runtime]() using Swift Package Manager:

https://github.com/AndrewBarba/swift-compute-runtime

Projects

Connect your code to Swift Cloud

Web Assembly

Compile your Swift applications to web assembly

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.

Swift Foundation and Dispatch

  • FoundationNetworking types, such as URLSession and related APIs

  • FileManager

  • Host

  • Notification

  • NotificationQueue

  • NSKeyedArchiver

  • NSKeyedArchiverHelpers

  • NSKeyedCoderOldStyleArray

  • NSKeyedUnarchiver

  • NSNotification

  • NSSpecialValue

  • Port

  • PortMessage

  • Process

  • ProcessInfo (Partially available since 5.7)

  • PropertyListEncoder

  • RunLoop

  • Stream

  • Thread

  • Timer

  • UserDefaults

Swift Cloud is made possible by the incredible 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.

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:

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.

SwiftWasm
The Foundation core library
the Dispatch core library
the lack of standardized multi-threading support
we invite you to contribute

Dictionaries

Domains

Connect custom domains

Origins

Fetch data in your application

Metrics

Deployments

Deploy your code to Swift Cloud

Plans & Billing

Teams

Logs