【问题标题】:How to extract a path-param from a Reitit backend end route如何从 Reitit 后端路由中提取路径参数
【发布时间】:2020-06-06 09:51:25
【问题描述】:

如何从 Reitit 后端 Clojure 路由中获取路径参数?我正在尝试通过以下方式获取与 :id 关联的 val,但在 REPL 中不断收到 404 file not found 错误。

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

我已尝试使用https://luminusweb.com/docs/routes.htmlhttps://github.com/metosin/reitit/blob/master/README.md 的文档。

【问题讨论】:

    标签: clojure path-parameter reitit


    【解决方案1】:

    从请求中解构路径参数,然后提取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 获得的文档和示例。如https://clojureverse.org/t/how-do-you-accomplish-spa-re-frame-teardown/5516/6 所述,使用了控制器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-26
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多