2016-04-15 30 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)是通过拦截器链传递的东西,它包含请求映射其他项目。 –