This commit is contained in:
paku 2024-12-20 15:15:04 +09:00
parent 09c5a126be
commit d20dbe2649
3 changed files with 5 additions and 5 deletions

View file

@ -73,9 +73,9 @@ Routes are generated automatically from packages under `:example/routes`:
### Dynamic Routing ### Dynamic Routing
Dynamic routes use square brackets to indicate parameters. For example: Dynamic routes use `< >` to indicate parameters. For example:
`/src/routes/user/[id].lisp` → `/user/[id]` `/src/routes/user/<id>.lisp` → `/user/:id`
In the handlers, you can access the value of `id` through the `params` argument. In the handlers, you can access the value of `id` through the `params` argument.

View file

@ -34,7 +34,7 @@
(regex-replace "/index$" path ""))) (regex-replace "/index$" path "")))
(defun bracket->colon (path) (defun bracket->colon (path)
(regex-replace-all "\\[(.*?)\\]" path ":\\1")) (regex-replace-all "<(.*?)>" path ":\\1"))
(defun path->uri (path) (defun path->uri (path)
(bracket->colon (remove-index path))) (bracket->colon (remove-index path)))

View file

@ -23,8 +23,8 @@
(ok (string= (path->uri "/nested/index") "/nested"))) (ok (string= (path->uri "/nested/index") "/nested")))
(testing "dynamic path" (testing "dynamic path"
(ok (string= (path->uri "/user/[id]") "/user/:id")) (ok (string= (path->uri "/user/<id>") "/user/:id"))
(ok (string= (path->uri "/location/[country]/[city]") "/location/:country/:city" )))) (ok (string= (path->uri "/location/<country>/<city>") "/location/:country/:city" ))))
(deftest package-test (deftest package-test
(testing "normal case" (testing "normal case"