Fork me on GitHub

@dave.tenny there was a broken safety assertion. having a :format key in the options, should fail with a descriptive message to use :formats. Fixed it, try this:


(def app
    {:formats (m/create (-> m/default-options (msgpack/with-msgpack-format)))}
    (GET "/" []
      (ok {:kikka "kukka"}))))

(app {:uri "/", :request-method :get, :headers {"accept" "application/msgpack"}})
;{:status 200,
; :headers {"Content-Type" "application/msgpack; charset=utf-8"},
; :body #object[ 0x43296161 "[email protected]"],
; :muuntaja/format "application/msgpack"}


the next alpha will fail with invalid input:


(def app
    {:format (m/create (-> m/default-options (msgpack/with-msgpack-format)))}
    (GET "/" []
      (ok {:kikka "kukka"}))))
;CompilerException java.lang.AssertionError: Assert failed: ERROR: Option [:format] is not used with 1.2.0 or later.
;Compojure-api uses now Muuntaja insted of ring-middleware-format,
;the new formatting options for it should be under [:formats]. See
;[[api-middleware]] documentation for more details.


Hey are there any examples for having authenticated and unauthenticated endpoints with compojure api and swagger?


Also how can I add the authentication middleware to compojure api routes in case it has more than 1 parameters?


This may not answer your question, but we use things like buddy.auth.middleware/wrap-authentication in our ring handlers for authentication. I'm not clear on how we manage to have a mix of authenticated and unauthenticated endpoints even though I implemented it. Ultimately ring handers for all though, I think.


Ah, there it is. Our authenticated endpoints use a context with :middleware option and authentication routines. Our unauthenticated enpoints aren't grouped in that context. I know, a code sample would help but can't easily give you one.


@dave.tenny Nice I think I understand what you mean.. what if your middleware have more than the handler parameters?


I'm unclear on what you mean about the handler parameters. However note that you can update the request as it's passed down the handler chain, adding headers. E.g. if you've authenticated a user you might add a user or identity token to the headers. I think. It's been a while since I worried about this stuff.


Right.. What I mean is that normally a middleware wrapper will be of arity 1 and take a ring handler as a parameter and then it is just injected in the :middleware keyword. In my case my middleware has additional dependencies which I am not sure how to pass in the :middleware keyword


Sorry, don't know.


If you're truly stuck perhaps dynamic bindings?


I still consider myself to be a ring/compojure rookie, so I'll bow out of the lame suggestion department for now.


No problem thanks for your help! really appreciate I may even got this wrong in the first place since I am a rookie as well xD


Any ideas why I get CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol when passing a binded vector into :middleware rather than passing it directly?


for instance :middleware [] works fine but (let [mw []] ( ... :middleware mw ...)) throws the above error