我正在做一个简单的API,它需要从json/edn请求中读取主体参数。我试图让程序将内容作为edn对象进行回显,但我的路由似乎不起作用。
(def routes
(route/expand-routes
#{["/echo" :get [body-params/body-params print-response] :route-name :greet]}))拦截器
(def print-response {:name ::print-response
:leave (fn [context]
(let [content-type (get-in context [:request :content-type])
updated-response (assoc (-> context :response) :headers {"Content-Type" content-type}
:status 200
:body (get-in context [:request] :edn-params))]
(assoc context :response updated-response))
)
}
)发布于 2021-10-19 07:48:26
fix :在body-params周围加上parantheses解释body-params实际上body-params是一个创建拦截器的高阶函数,因此必须调用它
(def routes
(route/expand-routes
#{["/echo" :get [(body-params/body-params) print-response] :route-name :greet]}))https://stackoverflow.com/questions/69626331
复制相似问题