$ show pointfreeco/swift-web
pointfreeco/swift-web is a collection of modular Swift libraries for building server-side web applications. It provides a functional approach to routing (ApplicativeRouter using partial isomorphisms and applicative combinators), a type-safe CSS DSL (Css module), an HTTP pipeline middleware system with phantom types for state safety (HttpPipeline), URL form encoding/decoding, HTML rendering integration, and signed cookie support. The architecture is highly modular: each library can be used independently. The codebase demonstrates advanced functional programming patterns from the Point-Free ecosystem, including applicative functors, optics, and monoids. It relies on Apple's SwiftNIO for server I/O and supports both macOS and Linux via Docker. The project is experimental but well-tested with snapshot testing. It is best suited for Swift developers seeking a functional, composable web framework foundation.
The LLM identified 5 files worth highlighting for reuse:
Defines a generic PartialIso<A, B> struct representing a partial isomorphism (invertible partial function). Provides composition, inversion, and conversion operators. This is a core building block for the router's bidirectional parsing/printing and can be reused in any Swift project requiring invertible transformations between types.
A custom Decoder implementation for URL-form-encoded data (x-www-form-urlencoded). Supports multiple parsing strategies: accumulateValues (flat key-value), brackets (nested structures with []), and bracketsWithIndices (with array indices). Also supports custom data and date decoding strategies, making it highly flexible for decoding form data into Swift Codable types.
Implements a composable Stylesheet type that is a monoid, allowing CSS rules to be combined with `<>`. Provides selectors (CssSelector), properties, media queries, keyframes, and nested rules. The DSL enables type-safe, composable CSS generation in Swift, with support for vendor prefixes via Prefixed values. This pattern is reusable for any Swift CSS generation library.
Defines the Middleware type as a function from Conn<I, A> to IO<Conn<J, B>>, where steps are phantom types (StatusLineOpen, HeadersOpen, BodyOpen, ResponseEnded) enforcing correct ordering. Provides combinators like writeStatus, writeHeader, closeHeaders, send, end, and redirect. This design allows building type-safe, composable HTTP middleware pipelines and can be extracted as a reusable pattern for functional middleware systems.
Provides functions for signing and optionally encrypting HTTP cookies using HMAC-SHA256 and AES-GCM. Supports verifying signed cookie values with a secret. Includes helpers for encoding/decoding data and Codable values. This component is self-contained and can be reused in any Swift web project requiring secure cookie management.