【问题标题】:Compojure-specific destructuring and query stringsCompojure 特定的解构和查询字符串
【发布时间】:2014-10-20 21:41:55
【问题描述】:

我正在尝试使用 compojure 在如下请求中访问参数 foo

/api/xyz?foo=bar 

compojure destructuring syntax 看起来不错,所以我想使用它。然而,以下只是为我提供“找不到页面”:

(defroutes app-routes    
  (GET "/api/xyz/:foo" [foo] (str "foo: " foo))
  (route/not-found "Page not found"))

这有点奇怪,因为下面的详细解构有效并给了我“foo:bar”:

(defroutes app-routes    
  (GET "/api/xyz" {{foo :foo} :params} (str "foo: " foo))
  (route/not-found "Page not found"))

我错过了什么?

【问题讨论】:

    标签: clojure compojure ring


    【解决方案1】:

    如果foo 始终作为 URL 参数传递,您希望您的代码如下所示:

    (defroutes app-routes    
      (GET "/api/xyz" [foo] (str "foo: " foo))
      (route/not-found "Page not found"))
    

    【讨论】:

      猜你喜欢
      • 2012-02-16
      • 2017-04-14
      • 1970-01-01
      • 2011-07-30
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多