2016-04-15 29 views

回答

2

通過Pedestal查詢參數are parsed automatically,並將得到的地圖放在:query-params密鑰下的請求地圖中。

舉一個簡單的例子,先從底座式服務模板,並使用以下定義:

(defn home-page 
    [request] 
    (ring-resp/response (format "Hello with params: %s" (:query-params request)))) 

(defroutes routes 
    [[["/" {:get home-page}]]]) 

現在,如果你瀏覽到http://localhost:8080/?param=true&other=1234,你應該看到Hello world with paramters: {:param "true", :other "1234"}

+0

謝謝。在你提供的鏈接中,它提供了關於「上下文」的討論(如下:當請求匹配這條路由時,攔截器的整個向量被推送到上下文中。)我很困惑,當它談論請求映射時「語境」? – Zuriar

+1

不完全。 [context](https://github.com/pedestal/pedestal/blob/master/guides/documentation/service-context-reference.md)是通過攔截器鏈傳遞的東西,它包含請求映射其他項目。 –