This pitch outlines an idea for a resource‑centric Swift server framework, intended for discussion and design exploration within SSWG. The core idea is to treat HTTP resources as first‑class types, rather than routing strings to handlers, addressing a common limitation of route‑centric frameworks where the HTTP resource model is implicit or obscured.
Inspired by the HTTP specification, the framework would model resources and their representations, with supported HTTP methods emerging naturally from resource capabilities.
Rather than registering routes, developers declare and compose resources hierarchically. Each resource explicitly defines which HTTP methods it supports and how representations are produced or consumed. The tree composition of URLs is inspired by SwiftUI.
Minimal example: product catalog microservice
@main
struct CatalogService: HTTPService {
var resources: some ResourceTree {
ResourceCollection<Product>("products") {
/// This handles GET /products
func get() async throws -> [Product] {
...
}
/// This handles POST /products
func post(_ product: ProductDraft) async throws -> Product {
...
}
}
}
}
struct Product: Resource {
let id: UUID
let name: String
let price: Decimal
}
struct ProductDraft: Codable {
let name: String
let price: Decimal
}
Here, /products is a concrete resource. Its supported HTTP methods and representations are defined directly in code, making HTTP semantics explicit rather than encoded in external routing configuration.
The API is work in progress, suggestions are welcome.