This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-10
Channels
- # aleph (3)
- # announcements (1)
- # architecture (16)
- # bangalore-clj (1)
- # beginners (65)
- # biff (5)
- # calva (23)
- # clj-kondo (6)
- # clj-otel (12)
- # clojure-austin (2)
- # clojure-europe (11)
- # clojure-norway (7)
- # clojure-uk (1)
- # clojuredesign-podcast (2)
- # clojurescript (18)
- # conjure (3)
- # datomic (1)
- # deps-new (18)
- # events (1)
- # hyperfiddle (14)
- # java (4)
- # malli (5)
- # off-topic (10)
- # pathom (13)
- # polylith (10)
- # practicalli (1)
- # re-frame (3)
- # reitit (16)
- # releases (1)
- # rum (5)
- # shadow-cljs (17)
I use integrant, among other thing it sets up a s3 cliënt. What is the "best" way to get the s3 cliënt into a handler function? Do I pass it down with closures? Do I attach it to the request with middleware? How do you deal with it?
Both are valid options. Personally I prefer passing dependencies down explicitly because then it’s very clear where the deps are coming from. I usually have a function that receives the dependencies from integrant and returns a reitit router. Here’s one example: https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/handler.clj#L51 https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/clj/lipas/backend/system.clj#L27
As an alternative, and as alluded to at the start, I perfer to stick my dependencies in an app-config that is injected into the requst via middleware:
https://github.com/dharrigan/startrek/blob/master/src/startrek/shared/middleware/app_config.clj
This is roughly how I had it before but I injected the clients separately, but al in one map is a good idea as well. Thanks!
Hi Friends, I’m migrating one API Rest from compojure-api to reitit and I have a question. I’ve been thinking about creating a new version of the API for reitit, refactoring the routes and adding swagger. My question is, can I run the old routes with compojure-api and the new ones with reitit at the same time?
Yes you can! I have done the exact same thing.
I put the reitit routes early in the ring middleware chain and check if they return a response. If not, I pass the request on to the next handler.
mmmm I’ll try that tmr, can I reach out to you?
Can you share a snippet?
Very schematically it looks like this (haven't confirmed this actually works but I think it should)
(def routes
["reitit/routes/here"])
(def reitit-handler
(reitit-ring/ring-handler
(reitit-ring/router
routes)))
(defn reitit-middleware
[handler]
(fn [request]
(or (reitit-handler request)
(handler request))))
(def app
(-> your-compojure-routes-middleware
reitit-middleware
;; other middleware
))
Also check out reloading-ring-handler
in the latest release of reitit.