Edge of Tomorrow: Full-Stack Swift on Both Sides of fetch

Hello lovely community,

I have been cooking something I’d like to show you:

While this web app certainly neither looks impressive nor does anything particularly useful, it packs quite a few things that have only been made possible very recently:

  • builds Embedded Swift WebAssembly with 6.4.x and swift-build (quite a recent achievement)
  • integrates ElementaryUI + BridgeJS in the frontend, including Fetch API networking
  • uses “NewCodable” (experimental) for shared Swift data types (both on the edge backend and web frontend)
  • uses async/await and throws like it’s nothing ; )
  • deploys Swift logic on Cloudflare Workers (edge runtime, ~107kB wasm fetch handler)

Find the source code here: GitHub - elementary-swift/example-cloudflare-worker: Full Stack Swift web tech demo using WebAssembly · GitHub

Now, "NewCodable" is still experimental, Swift 6.4 is not out yet, and using Embedded Swift still has a few usability quirks - but I think it is pretty exciting to see the steady progress in this area.

Feel free to ask any question!

14 Likes

This is really great. Thanks for sharing.

I would love to hear if the FetchHTTPClient that we have prototyped could work for this as well. It is equally experimental as the NewCodable API.

I initially planned on using it, but then - oh, what horrors my eyes had to witness - in just the second line!!

import Foundation

So, with a single tear of disappointment rolling down my cheek, I silently shook my head and closed that GitHub tab again...

Good point. We definitely want to get rid of the full Foundation dependency here.

I know of this PR - not sure if that is already all it takes to make it "embedded wasm" portable, but it's a start:

1 Like

Super cool! How's the debugging experience for the client side code?