title: compojure routes : How to call a function with dependencies from a route?
body: <p>The idea is to call a certain function when a route matches. That function has dependencies . I'm new to clojure and compojure and this approach could be wrong.
  But still, this is what I try to achieve.</p>
  <pre><code>(defroutes my-routes (GET &quot;/user/list&quot;
                        []
                     (list-users)) ; where list-users is for example (partial list-users user-service)
  </code></pre>
  <p>Since I didn't find a way to do this with <code>defroutes</code>, I tried to setup the routes &quot;dynamically&quot;.</p>
  <pre><code> (defn define-routes [services]
    (routes
      (GET &quot;/user/:id&quot;
           [id]
        ((:show-user services) id))
      (GET &quot;/user/list&quot;
           []
        ((:list-users services))))
  </code></pre>
  <p>When I start jetty with the routes defined like this,</p>
  <pre><code> (defn app [services]
       (j/run-jetty (define-routes services) {:port 3000 :join? false}))
  </code></pre>
  <p>every call leads to an exception:</p>
  <pre><code>java.lang.NullPointerException: Response map is nil
  </code></pre>
  <p>Is there a way to use defroutes and call functions where dependecies are injected or is ok to do it the way I tried, but I'm doing it wrong?</p>