6
votes

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!

1
To determine whether your problem is in the compojure route-definition or in the params not being extracted by wrap-params, can I recommend that you temporarily (defn public-routes [req] (println req)) so you can see the whole Ring request map? - duelin markers

1 Answers

1
votes

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