2016-04-11 21 views
1

我已經發布的數據至基座的終點「/我-後我已經排到那個終點爲這樣:從POST請求,獲得這個職位的身體數據,底座

[[["/" {:get landing} ^:interceptors [(body-params/body-params) ...] 
    ["/my-post {:post mypost-handler} 
    .... 

所以,在我看來這種手段。身體-PARAMS攔截器會火/ mypost太

在mypost處理程序,我有:

(defn mypost-handler 
    [request] 
    ****HOW TO ACCESS THEN FORM DATA HERE **** 
)  

我怎麼現在這裏訪問表單數據,我可以從印刷的要求看?我有一個#object [組織.eclipse.jetty.sever.HttpInputOverHTTP ..],這對我來說顯然需要進一步處理。

(我必須說,對於基座的文檔充其量非常粗略...)

回答

2

像這樣的東西應該工作。請注意mypost處理程序路由上的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)] 
    ] 
    ]]) 
0

mypost-handler充當環處理,我。即它應該接受一個Ring請求映射並返回一個Ring響應映射。因此,你可以期待一個典型的環請求結構:在你的路由表定義這樣的處理程序

(defn mypost-handler 
    [{:keys [headers params json-params path-params] :as request}] 
    ;; handle request 
    {:status 200 
    :body "ok"}) 

Here's more relevant info

+0

謝謝,但我仍然不確定我是如何獲取數據的。 – Zuriar