Fork me on GitHub
#ring-swagger
<
2016-03-05
>
Ruben W13:03:30

is anyone using compojure-api in combination with immutant-web? I’m a bit stuck figuring out how to pass my handler to the immutant web-server:

(require '[immutant.web               :as server])
(defapi api-handler
  (GET "/ping" []
    (ok {:ping "pong"})))

(server/run api-handler {:host “localhost” :port 12345})
gives me ClassCastException compojure.api.routes.Route cannot be cast to io.undertow.server.HttpHandler org.projectodd.wunderboss.web.undertow.UndertowWeb.registerHandler (UndertowWeb.java:68) I’ve can test the routes themselves and they work as expected with: (slurp (:body (api-handler {:request-method :get :uri “/ping”})))

Ruben W13:03:34

with compojure-api 0.24.0 this was still working ..

juhoteperi13:03:17

Looks like Immutant is doing some magic to turn functions to handlers. Regular compojure and pre-1.0 compojure-api handler is normal function. In 1.0 it is special record which implements function interfaces.

ikitommi13:03:25

you might need to wrap the api-routes into a function

ikitommi13:03:13

(partial api-routes) could work

ikitommi13:03:43

or #(api-routes %)

Ruben W13:03:29

@ikitommi: tnx, (partial api-routes) gives the same error, #(api-routes %) works though

Ruben W13:03:40

although, none of my routes are actually reachable

juhoteperi13:03:01

Though fn? could be justified, but that's what causes it to not convert the handler to HttpHandler

Ruben W13:03:19

I’ll switch to http-kit I guess

juhoteperi13:03:27

You can manually convert the handler to HttpHandler by calling immutant.web.undertow/http-handler

juhoteperi13:03:15

Though I would have thought that #(...) works also

Ruben W13:03:29

well it compiles, maybe something else is going on, but somehow all of my routes (/ping, /swagger.json) return 404

Ruben W13:03:41

create-http-handler also compiles (but is only available since 2.1.3-SNAPSHOT), but still keeps giving 404s

Ruben W13:03:52

http-kit works fine 😕

Ruben W14:03:33

hm appearently it’s just immutant-web 2.1.2, 2.1.1 also serves my routes