This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-08
Channels
- # announcements (42)
- # aws (2)
- # babashka (69)
- # beginners (38)
- # calva (18)
- # cider (39)
- # circleci (1)
- # clj-commons (10)
- # cljs-dev (2)
- # clojure (36)
- # clojure-australia (14)
- # clojure-europe (25)
- # clojure-gamedev (40)
- # clojure-losangeles (4)
- # clojure-nl (5)
- # clojure-sweden (1)
- # clojure-uk (5)
- # clojurescript (133)
- # core-logic (24)
- # cursive (7)
- # datalevin (4)
- # datascript (3)
- # figwheel-main (1)
- # fulcro (45)
- # honeysql (1)
- # integrant (43)
- # introduce-yourself (1)
- # jobs (4)
- # leiningen (3)
- # lsp (32)
- # nextjournal (9)
- # pathom (18)
- # polylith (21)
- # portal (65)
- # re-frame (6)
- # releases (1)
- # remote-jobs (1)
- # reveal (12)
- # rewrite-clj (1)
- # sci (84)
- # tools-deps (22)
Hello, when I am using integrant, I have a config.edn listing down all the configuration details. May I know what is best practice when my routes in my ring-server needs to reference some of these details?
Maybe the part that would be helpful is knowing how to change more complicated ring routes into integrant components :thinking_face:
Like if I have
(def config
{:adapter/jetty {:port 8080, :handler (ig/ref :handler/all)}
:handler/greet1 {:name "Alice"}
:handler/greet2 {:name "Bobby"}})
(defmethod ig/init-key :adapter/jetty [_ {:keys [handler] :as opts}]
(jetty/run-jetty handler (-> opts (dissoc :handler) (assoc :join? false))))
(defmethod ig/init-key :handler/greet1 [_ {:keys [name]}]
(fn [_] (resp/response (str "Hello " name))))
(defmethod ig/init-key :handler/greet2 [_ {:keys [name]}]
(fn [_] (resp/response (str "Hello " name))))
I don't really know how to do a :handler/all
for this with compojure(require '[reitit.core :as r])
(defmethod ig/init-key :my/router
[_ {:keys [routes]}]
(r/router
routes))
(def config
{:adapter/jetty {:port 8080, :handler (ig/ref :my/router)}
:my/router {:routes
[["/greet1" (ig/ref :handler/greet1)]
["/greet2" (ig/ref :handler/greet2)]]}
:handler/greet1 {:name "Alice"}
:handler/greet2 {:name "Bobby"}})
yeap supposing I use compojure. Typically it will be something like
(defroutes routes-handler
(GET "/greet1" [] (greet1)
(GET "/greet2" [] (greet2))
how might this be turned to integrant then :thinking_face:I'm not too familiar with compojure myself, but I assume it creates a var named routes-handler
That might not work actually, since it's a macro and needs the handlers at compile time
Here is an article about compojure-api + integrant https://the-frey.github.io/2017/12/14/compojure-and-integrant
Oh yeap just found that right before you replied but couldn't quite understand it since they left the compojure part out
Tho there's a sample project - https://github.com/the-frey/compojure-api-integrant/blob/master/src/compojure_api_integrant/handler.clj#L9 but I don't really understand where the api function (?) came from
but guess trying to avoid doing both that and refactoring of integrant stuff concurrently
oh for the integrant case - am already using it but currently the routes aren't being handled by integrant to handle the dependencies, so a hack-ish way to copy the integrant state was previously used - am trying to fix that currently haha
am not sure if im also slightly confused - because ^ is also to get integrant-repl is work correctly (and i read that integrrant and integrant-repl aren't exactly the same)
also I realise that in the guide compojure being used is https://github.com/metosin/compojure-api and am currently using https://github.com/weavejester/compojure
integrant-repl is an extension on integrant. Not sure what you mean by "they are not the same"
i was reading ... https://practical.li/clojure-webapps/repl-driven-development/integrant-repl/#integrant-repl-and-integrant
I guess for clearer context - in my project integrant-repl
is already being used but running go
doesn't setup the full system
currently have run another function that copies integrant-repl.state/system
into an atom. which the routes access using stuff like get-in
to take values from
But anyway thanks for your help @kevin.van.rooijen ! 😄 Maybe I'll start with the refactoring to reitit
I’m on my phone but I did this by putting the compojure “app” into my integrant state, and then any time I changed a route I (halt!) and (go) to restart the app
When I’m on my computer I can show what I’ve done with actual code