Static Response1
HTTP throughput for a static response.
Declare inputs, limits and documentation in one place.
Stream server-sent events or WebSocket messages from a regular handler.
Compose pages from stacks, spacers and modifiers.
Declare services and their dependencies. Startup order and graceful shutdown follow from the declaration.
@Handler(method: .GET, path: "greet/:name")
struct GetGreet {
@PathParameter("name")
var name: String
func handle() async throws -> String {
"Hello, \(name)!"
}
}
@Handler(method: .GET, path: "prices")
struct GetPrices {
func handle() async throws -> SSEResponse {
SSEResponse { continuation in
for await price in priceFeed {
await continuation.yield(data: price, event: "price")
}
continuation.finish()
}
}
}
struct ProfileCard: View {
let name: String
var body: some View {
HStack {
Image()
.src("/avatar.jpg")
.frame(width: ._13, height: ._13)
.borderRadius(.percent(._100))
Text(string: name)
.fontSize(.headline)
Spacer()
}
.gap(._6)
.padding(._7)
.backgroundColor(.secondaryGroupedBackground)
}
}
let app = WebServiceApp {
GreetService {
HTTP(host: "0.0.0.0", port: 8080) {
Logging.resolve
}
WebUI {
HTTP.resolve
}
}
}
try await app.run()
struct LikeButton: View {
let likes: Int
var body: some View {
HStack {
Text(string: "\(likes) likes")
.fontWeight(.bold)
Button("Like")
.type(.button)
.title("Like this post")
.hxPost("/like")
.hxSwap(.outerHTML)
}
.gap(._4)
.padding(._6)
.backgroundColor(.secondaryGroupedBackground)
.borderRadius(._5)
}
}
Every element and attribute of the WHATWG spec, as Swift.
Layout, type and color, built in.
Typed htmx attributes update the page from the server.
HTTP throughput for a static response.
HTTP throughput on an endpoint that parses cookies.
A table rendered from data on every request.
The same page on every request.
RFC 9110 dates, as found in headers and cookies.
BCP 47 language tags, for localized responses.
WebService
Runs your app and its services.
WebServiceCore
Service and plugin protocols.
WebServiceLogging
Logging through swift-log.
WebServiceHTTP
HTTP server and declarative endpoints.
WebServiceWS
WebSockets.
WebServiceSSE
Server-sent events.
WebUICore
Typed HTML, complete to the WHATWG spec.
WebUI
Design system and layout.
HTMX
Typed htmx attributes.
.package(url: "https://github.com/antonlorani/swift-webservices.git", from: "0.36.0")