Skip to content

About

Turn any iOS app into a full HTTPS/WebSocket REST API Server

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

SwiftCoreWeb

License Swift Platform SwiftNIO Vue SQLite Docs OpenSSF Baseline Security Policy Contributing Donate with PayPal Donate with BITCOIN Star History

Your iPhone can run a real web server. SwiftCoreWeb turns any iOS 15+ app into a full HTTP/HTTPS/WebSocket backend, no separate server needed. Same fluent, Minimal-API feel .NET developers already love, done in idiomatic Swift, with zero runtime reflection.


Requirements

  • iOS 15.0+ deployment target
  • Xcode 16+ / Swift 6 language mode (macros require a Swift 5.9+ toolchain at compile time only — zero runtime cost)
  • Dependencies: swift-nio, swift-nio-transport-services, swift-syntax (macros only). Everything else — TLS, JWT signing/verification, logging, network monitoring — uses system frameworks (Security, CryptoKit, os.Logger, Network).

Hello World

import SwiftCoreWeb

let app = WebApplication.createBuilder().build()
app.mapGet("/hello") { "Hello, world!" }
try await app.runAsync()

Binds to 127.0.0.1:8080 by default — secure by default, no LAN exposure until you explicitly opt in with builder.listenOnAllInterfaces().

Your first interactive page

A click in the browser runs Swift on the server, and the page updates — no client-side JS to write.

struct CounterPage: Page {
    static let template = "counter.html"
    var count = 0

    mutating func onEvent(_ event: String, _ ctx: PageContext) async throws -> PageAction {
        if event == "increment" { count += 1 }
        return .render
    }
}

app.useVue()
app.usePages(root: .bundle("Views"))
app.mapPage("/counter", CounterPage.self)

Views/counter.html — a Vue template, nothing else:

<button @click="$swift('increment')">Count: {{ count }}</button>

Three rules: form fields (none here) are what the user edits; every other property is server state the browser can see but not change; $swift('name') calls onEvent("name") in Swift. See docs/web/LIVE_PAGES_GUIDE.md for every input type, validation, and session state.


Core concepts

WebApplication.createBuilder() gives you a fluent builder for ports/TLS/limits/DI, one router that mixes Minimal API closures and macro-based @Controllers, a middleware pipeline (auth, CORS, security headers, logging), zero-build Vue or a full Vite workflow for the frontend, and a TestHost that runs the real production pipeline in-memory. Every one of these has its own short guide with runnable examples — the full index is docs/README.md:


Showcase

Showcase/ is a complete, real end-to-end sample app — not a toy. It compiles against the actual API, and includes:

  • A SwiftUI app whose device screen shows the on-device dashboard while / keeps serving the site to browsers
  • A macro-based @Controller alongside closure Minimal API routes, on the same server
  • Two authentication schemes: JWT and a custom API-key header
  • SwiftUI ScenePhase lifecycle binding, plus keep-awake

It also walks through the three frontend workflows you'll actually use, and ships ready-to-copy Info.plist keys, vite.config.js, and both scripts:

  • Vite on the Mac with API proxying
  • on-device dev-deploy with live reload
  • a production Xcode build phase that copies dist/ into the bundle

See Showcase/README.md for the full walkthrough and how to wire the sample into an Xcode project. It ships as source files, not an .xcodeproj, since the framework itself is SPM-only.


On-device dashboard and .NET naming table

Two more things worth knowing exist, kept out of this file to keep it short:

  • On-device dashboard — turn the device's own screen into a live console (request rate, latency, CPU/memory/battery/thermal state) instead of whatever your app would otherwise show. One line of SwiftUI (SwiftCoreWebDashboardView(app: app)), opt-in library target, the HTTP server keeps serving pages exactly as before.
  • .NET naming table — coming from ASP.NET Core Minimal APIs? Every WebApplication.CreateBuilder()/MapGet/UseAuthentication/etc. has a direct SwiftCoreWeb equivalent, listed side by side.

License

SwiftCoreWeb is licensed under the PolyForm Noncommercial License 1.0.0.

  • Free for noncommercial use. Personal projects, education, research, and evaluation are all fine at no cost.
  • Commercial use requires a separate commercialization agreement with the author. If your use case makes or supports revenue, get in touch before shipping it.
  • The source is publicly readable on GitHub, but this is not an OSI-approved open-source license. SwiftCoreWeb is source-available, not open-source — please don't call it open-source in code, docs, or conversation.

The full license text is in LICENSE at the repository root. Third-party components embedded in this package (the Vue 3 runtime, SwiftNIO, swift-nio-transport-services) keep their own upstream licenses and required notices — see LICENSE-THIRD-PARTY.

Want to contribute? Read CONTRIBUTING.md and the Code of Conduct. Found a security issue? See SECURITY.md, don't open a public issue.


Support Development

If this project has been useful to you, consider a small donation. Every contribution helps fund new features and keep the project active.

Scan the code below with your wallet, or copy the address. Alternatively you can donate via PayPal.

Donate with BTC (Bitcoin)
BTC Address (SegWit) : bc1q6rj0uuwu9k2fvs5n5elmqy9v4ljazhexejykjm

About

Turn any iOS app into a full HTTPS/WebSocket REST API Server

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages