1
如何將URL參數獲取到Pedestal中的請求映射中?我假設這需要使用攔截器?然而,Pedestal文檔(或嚴重缺乏)並不能完全清楚這一點。謝謝。如何獲取Pedestal中的URL查詢參數?
如何將URL參數獲取到Pedestal中的請求映射中?我假設這需要使用攔截器?然而,Pedestal文檔(或嚴重缺乏)並不能完全清楚這一點。謝謝。如何獲取Pedestal中的URL查詢參數?
通過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"}
。
謝謝。在你提供的鏈接中,它提供了關於「上下文」的討論(如下:當請求匹配這條路由時,攔截器的整個向量被推送到上下文中。)我很困惑,當它談論請求映射時「語境」? – Zuriar
不完全。 [context](https://github.com/pedestal/pedestal/blob/master/guides/documentation/service-context-reference.md)是通過攔截器鏈傳遞的東西,它包含請求映射其他項目。 –