1

Using compojure-api, as in:

(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)))))

how do I access the ring-session?

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • I suggest inspecting what `defapi` expands to. Especially what the `restructure` part expands to. – muhuk Oct 14 '15 at 05:33

1 Answers1

0

based on docs from here: https://github.com/metosin/compojure-api/blob/master/src/compojure/api/core.clj , defapi is the following macro:

(defmacro defapi
  [name & body]
  `(def ~name
     (api ~@body)))

as you can see it just defines var with the result of api macro call (and api creates a ring handler)

so you could use it without defapi, and wrap ring session:

(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))

I guess after that you should be able to use the session normally, as described in https://github.com/ring-clojure/ring/wiki/Sessions . Haven't tester it, but i think it's the right way

leetwinski
  • 17,408
  • 2
  • 18
  • 42