ring-swagger & compojure-api
llsouder 2018-10-02T00:44:13.000100Z

Looking to make a simple rest like api and I found

 (sweet/GET "/ping" []
            (response/ok {:ping "pong"})))

llsouder 2018-10-02T00:44:29.000100Z


llsouder 2018-10-02T00:44:50.000100Z

(def app
    (sweet/GET "/hello" []
       :query-params [name :- String]
       (response/ok {:message (str "Hello, " name)}))))

llsouder 2018-10-02T00:45:39.000100Z

but what do I do with them? neither one produces a route.

llsouder 2018-10-02T00:46:13.000100Z

tried calling (app) in my (defroutes... that didn't go well.

llsouder 2018-10-02T00:46:56.000100Z

I am missing a key piece in the examples I am finding.

ikitommi 2018-10-02T03:20:47.000100Z

@llsouder app is a ring-handler (function), you can call it with a request

llsouder 2018-10-02T09:22:07.000100Z

@ikitommi don't I have to "register" it somewhere? the basic handler examples make a function called handler then do something like (server handler {:port 3000}) or put it in the project.cjl as :ring {:handler handler}

llsouder 2018-10-02T09:23:12.000100Z

I don't see this working for me since I already have other routes defined.


@llsouder you should register the same way you register other routes handlers


(run-jetty app ... is a way

llsouder 2018-10-02T10:59:17.000100Z

@mping I am finding lots of handler examples but nothing about the ways to register handlers.


@llsouder how do you start your app?

llsouder 2018-10-02T10:59:53.000100Z

In the end, I will push to heroku or aws

llsouder 2018-10-02T11:00:17.000100Z

using the luminus template at the moment

llsouder 2018-10-02T11:00:51.000100Z

so running an uberjar


how do you configure your app handler?

llsouder 2018-10-02T11:07:11.000100Z

In a route namespace and using some (defroute... ) stuff

ikitommi 2018-10-02T11:46:51.000100Z

luminus has some nice guides on how to run the app: http://www.luminusweb.net/docs#running_the_application

ikitommi 2018-10-02T11:48:34.000100Z

if you want to compose you top-level ring handler from api & other stuff, you can say:

(def handler
    (routes api some-other-routes)