使用compojure-api,如下所示:
(defapi app
(swagger-ui)
(swagger-docs
{:info {:title "Sample api"}})
(GET* "/" []
:no-doc true
(ok "hello world"))
(context* "/api" []
:tags ["thingie"]
(GET* "/plus" []
:return Long
:query-params [x :- Long, {y :- Long 1}]
:summary "x+y with query-parameters. y defaults to 1."
(ok (+ x y)))))如何访问ring-session?
发布于 2015-10-14 23:35:39
基于此处的文档:https://github.com/metosin/compojure-api/blob/master/src/compojure/api/core.clj,defapi是以下宏:
(defmacro defapi
[name & body]
`(def ~name
(api ~@body)))正如您所看到的,它只是使用api宏调用的结果定义了var (并且api创建了一个环处理程序)
所以你可以在不使用defapi的情况下使用它,并包装振铃会话:
(def app
(-> (api (swagger-ui)
(swagger-docs
{:info {:title "Sample api"}})
(GET* "/" []
:no-doc true
(ok "hello world"))
(context* "/api" []
:tags ["thingie"]
(GET* "/plus" []
:return Long
:query-params [x :- Long, {y :- Long 1}]
:summary "x+y with query-parameters. y defaults to 1."
(ok (+ x y))
ring.middleware.session/wrap-session))我猜在那之后,您应该能够正常使用会话,如https://github.com/ring-clojure/ring/wiki/Sessions中所述。我还没有测试过,但我认为这是正确的方法
https://stackoverflow.com/questions/33107175
复制相似问题