diff --git a/README.md b/README.md index fd8622c..43e8ae3 100644 --- a/README.md +++ b/README.md @@ -73,9 +73,9 @@ Routes are generated automatically from packages under `:example/routes`: ### 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/.lisp` → `/user/:id` In the handlers, you can access the value of `id` through the `params` argument. diff --git a/src/router.lisp b/src/router.lisp index 3c75566..9f974c3 100644 --- a/src/router.lisp +++ b/src/router.lisp @@ -34,7 +34,7 @@ (regex-replace "/index$" path ""))) (defun bracket->colon (path) - (regex-replace-all "\\[(.*?)\\]" path ":\\1")) + (regex-replace-all "<(.*?)>" path ":\\1")) (defun path->uri (path) (bracket->colon (remove-index path))) diff --git a/tests/router.lisp b/tests/router.lisp index 0196212..564c06d 100644 --- a/tests/router.lisp +++ b/tests/router.lisp @@ -23,8 +23,8 @@ (ok (string= (path->uri "/nested/index") "/nested"))) (testing "dynamic path" - (ok (string= (path->uri "/user/[id]") "/user/:id")) - (ok (string= (path->uri "/location/[country]/[city]") "/location/:country/:city" )))) + (ok (string= (path->uri "/user/") "/user/:id")) + (ok (string= (path->uri "/location//") "/location/:country/:city" )))) (deftest package-test (testing "normal case"