Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compojure route params empty

My Compojure web app ([compojure "1.0.1"]) always receives an empty parameter map, despite adding wrap-params etc. Code sample below:

(defroutes public-routes
  (PUT "/something" {params :params}
      (println (str "Params: " params))
      (do-put-something params)))

(def myapp 
  (-> public-routes
      ring-params/wrap-params))

(defn start-server []
  (future (jetty/run-jetty (var myapp) {:port 8080})))

I've tried adding the wrap-params, wrap-keyword-params and wrap-multipart-params but when I PUT to the endpoint using httpie (or my client), I find that params is always empty. Can anyone help?

Thanks!

like image 993
jamiei Avatar asked Oct 20 '12 16:10

jamiei


1 Answers

The only problem with your example code was that it lacks a ring response hash-map in the route body. The solution is evaluate to a ring response instead of using println. When you call println in your route it prints to standard out where the server process is running, which has nothing to do with the response to the API call.

(defroutes public-routes
  (PUT "/something" {params :params}
    {:status 200
     :body (str "Params: " params)}))

This produces a 200 response with Params: {"foo" "bar"} as the response body.

I am using this to test your PUT route:

curl -X PUT -d "foo=bar" http://127.0.0.1:8080/something
like image 105
rplevy Avatar answered Sep 28 '22 02:09

rplevy