我已将数据发布到基座端点“/my-post。我已按如下方式路由该端点:
[[["/" {:get landing} ^:interceptors [(body-params/body-params) ...]
["/my-post {:post mypost-handler}
....
Run Code Online (Sandbox Code Playgroud)
所以在我看来,这意味着 body-params 拦截器也会针对 /my-post 触发。
在我的后处理程序中我有:
(defn mypost-handler
[request]
****HOW TO ACCESS THEN FORM DATA HERE ****
)
Run Code Online (Sandbox Code Playgroud)
我现在如何访问此处的表单数据?我可以从打印请求中看到我有一个 #object[org.eclipse.jetty.sever.HttpInputOverHTTP..] ,它显然需要进一步处理才能对我有用。
(我必须说,Pedestal 的文档充其量只是相当粗略......)
像这样的东西应该有效。注意 mypost-handler 路由上的 body-params 拦截器
(defn mypost-handler
[{:keys [headers params json-params path-params] :as request}]
;; json-params is the posted json, so
;; (:name json-params) will be the value (i.e. John) of name property of the posted json {"name": "John"}
;; handle request
{:status 200
:body "ok"})
(defroutes routes
[[["/mypost-handler" {:post mypost-handler}
^:interceptors [(body-params/body-params)]
]
]])
Run Code Online (Sandbox Code Playgroud)