This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-25
Channels
- # aws (1)
- # bangalore-clj (9)
- # boot (97)
- # capetown (1)
- # cider (4)
- # clara (1)
- # cljs-dev (2)
- # cljsrn (109)
- # clojure (258)
- # clojure-finland (3)
- # clojure-greece (2)
- # clojure-italy (1)
- # clojure-russia (33)
- # clojure-spec (41)
- # clojure-uk (46)
- # clojurescript (57)
- # component (17)
- # core-async (6)
- # datomic (13)
- # devcards (10)
- # dirac (2)
- # euroclojure (1)
- # figwheel (1)
- # funcool (1)
- # hoplon (472)
- # luminus (17)
- # off-topic (1)
- # om (16)
- # onyx (40)
- # pedestal (14)
- # proton (12)
- # re-frame (27)
- # reagent (15)
- # ring-swagger (2)
- # specter (5)
- # testing (4)
- # untangled (258)
- # vim (4)
Is it counterproductive to make to try and make pedestal route handlers components?
I’m wanting to make a component that can have a database and mqtt client passed in and if specific HTTP routes get hit, it can write to the database and then put a message on an mqtt channel
(def routes (clojure.set/union #{} foo/routes-with-deps-injected))
I have one router component that builds the route handlers, passing in the required components
I have thought about going the next step and having each router handler be its own component and take advantage of the component machinery for dependency graphs, but it felt like too much work for too little payoff in my case
Do you have a snippet?
Do you have your routes nested in a subsystem that gets built on start?
@tetriscodes have a look at this code https://github.com/pointslope/elements/blob/master/src/pointslope/elements/pedestal.clj#L68-L95 The idea is that any components that the Pedestal component depends on are automatically added to the request map by the using-component
interceptor.
if this is my system definition:
you can see that the Pedestal component depends on :config
if I then add the interceptor (using-component :config)
to one of my routes, then the handler for that route will find the :config
key on the request map with a reference to the configurator component
using this scheme you can expose any component to your handlers (via the request map) simply by making the pedestal component depend on it.
this is not "the one true way" to do what you want, but it is "a way" to do so...
@christianromney thank you. I will take a look