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