A small, dependency-free routing library for Swift
- Swift 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| docs | ||
| Sources/Atlas | ||
| Tests | ||
| README.md | ||
Atlas
A small, dependency-free routing library for Swift. 🗺️
Atlas turns a URL into a value your code can switch on. It does not do networking, it does not do views, and it will never grow a plugin system.
Installing
dependencies: [
.package(url: "https://example.com/atlas.git", from: "2.1.0")
]
Using it
let router = Router {
Route("/users/:id") { UserRoute(id: $0["id"]) }
Route("/posts/:slug/comments") { CommentsRoute(slug: $0["slug"]) }
}
switch router.match(url) {
case .user(let id): show(user: id)
case .comments(let slug): show(comments: slug)
case .none: showNotFound()
}
What it supports
| Pattern | Matches | Captures |
|---|---|---|
/users/:id |
/users/42 |
id = "42" |
/files/*path |
/files/a/b/c.txt |
path = "a/b/c.txt" |
/posts/:slug |
/posts/hello-world |
slug |
/health |
/health only |
— |
Status
- Path parameters
- Wildcard segments
- Query strings
- Route priorities — see #2
- A macro-based DSL
Thanks to @reviewer for the report in #1.
Licence
MIT.
