1

I hope I can explain this in such a way that it makes sense!

I'm using Liberator to prototype some web services that I need to expose to clients and have route(s) defined like so:

(defroutes fish
  (context "/fish"
           []
           (ANY "/cod/:id/count"
                [id]
                (cod-fish id))))

(def handler
  (-> fish
      wrap-params
      path-wrapper))

The intention of path-wrapper is to output some information about the matched path. It currently looks like so:

(defn path-wrapper
  [handler]
  (fn [request]
    (println "in" (:request-method request) (:uri request))
    (let [response (handler request)]
      (println "out")
      response)))

This prints out what you'd expect:

in :get /fish/cod/123/count
out

However, what I'd like it to print out is:

in :get /fish/cod/:id/count
out

That is, the path that matched rather than the URI that matched it.

I'm almost certain that the answer is in Clout somewhere but I don't seem able to find it! :(

Any advice?

Cheers,

Peter

ordnungswidrig
  • 3,140
  • 1
  • 18
  • 29
peter
  • 177
  • 1
  • 10

1 Answers1

0

In cases like this I'm fond of putting in a debugging statement like:

(let [response .... ]
    (log/errorf "in: request was: %s" 
       (with-out-str (clojure.pprint/pprint request))
 ....

and look for the data you want in the output (then remove the statement) or if you have a working and modern emacs+cider environment you can add debugging to the function with C-uC-cC-c and catch the value of request that way. If the data you wan't is available it will likely be in that output. If you are not using a logging framework then remove the log and with-out-str parts and just call pprint directly.

Sorry if i'm misunderstanding or perhaps is's a typo in the question though:

(let [response handler]
      (println "out")
      response)

looks like it's returning the handler itself rather than the result of calling that handler, should it be :

(let [response (handler request)]
      (println "out")
       response)  
Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
  • to answer your second point; yes, it should have been a call to `handler` rather than the handler itself - thanks. – peter Sep 18 '15 at 07:51