Last active
August 17, 2025 23:14
-
-
Save carlynorama/c9ec1d4dc46b6080ee6dafed32e355fb to your computer and use it in GitHub Desktop.
Handy Router Extensions, Hummingbird
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Hummingbird | |
| extension Router { | |
| /// Motivation: the below won't take .redirect without `Response.` and I'm that lazy. | |
| /// router.get("c") { _, _ in Response.redirect(to: "test.html", type: .normal) } | |
| /// usage: | |
| /// router.autoReply("a", response: .init(status: .ok)) | |
| /// router.autoReply("b", response: .redirect(to: "test.html", type: .normal)) | |
| func autoReply(_ path:RouterPath, response:Response) { | |
| self.get(path, use: { _, _ in response}) | |
| } | |
| // Response.RedirectType isn't Sendable. | |
| // func redirect(path:RouterPath, to newPath:String, type:Response.RedirectType = .normal) { | |
| // self.get(path, use: { _, _ in Response.redirect(to: newPath, type: type)}) | |
| // } | |
| /// usage: | |
| /// router.redirect(path: "d", to: "test.html") | |
| func redirect(path:RouterPath, to newPath:String) { | |
| self.get(path, use: { _, _ in Response.redirect(to: newPath)}) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment