gpt4 book ai didi

clojure - 如何从 Reitit 后端路由中提取路径参数

转载 作者:行者123 更新时间:2023-12-04 12:24:35 29 4
gpt4 key购买 nike

您如何从 Reitit 后端 Clojure 路由中获取路径参数?我正在尝试获取与 :id 相关联的 val按照以下方式,但在 REPL 中不断出现 404 文件未找到错误。

["/foo/:id" {:get 
(fn [{:keys [path-params ]}]
(some-ns/some-fn (:id path-params)))}]

我曾尝试使用 https://luminusweb.com/docs/routes.html 处的文档和 https://github.com/metosin/reitit/blob/master/README.md .

最佳答案

从请求中解构路径参数,然后提取id。

(defn project-routes
"SPA routing"
[]
["" {:middleware [middleware/wrap-base
middleware/wrap-formats]}

["/foo"
["/bar/:id"
{:get (fn [{:keys [path-params] :as _req}]
(http-response/ok
(core/READ some-table
(Integer/valueOf (:id path-params)))))}]]])

https://github.com/luminus-framework/luminus-docs/blob/master/resources/md/sessions_cookies.md 获得的文档和示例.使用了 Controller ,如 https://clojureverse.org/t/how-do-you-accomplish-spa-re-frame-teardown/5516/6 所述.

关于clojure - 如何从 Reitit 后端路由中提取路径参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60763151/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com