Type-safe URL routing in Swift
summary
Shows a concrete, working Swift URL router that replaces stringly-typed handlers with applicative parser combinators producing typed outputs (e.g., city: String, year: Int), implements Functor/Applicative/Alternative and an enum-based recursive routes representation, and runs an optimizer that groups common path heads to merge duplicated match nodes so "foo" checks aren’t repeated. Demonstrates examples (hello/Budapest/2016), exports an open‑source library and playground, and notes limits: Vapor only supports three params and Swift hits “expression too complex” on large combinator expressions.
AI-written summary · about
chapters (17)
- 0:00Introduction and speaker intro
- 1:03What is URL routing
- 3:09Naive URL routing example
- 6:00Server-side routing limitations
- 8:08Vapor's type-safe approach
- 9:53Parser Combinators for routing
- 11:18Implementing URL parser
- 13:27Functor and applicative parsers
- 15:35Capture and conversion functions
- 17:22Applicative-style routing
- 19:53Testing type-safe routing
- 20:58Bug tracking in routing
- 22:02Enum-based routing structure
- 24:12Optimizing enum-based routing
- 26:40Open-sourcing the router
- 27:01Type-safe routing summary
- 28:35Q&A session
