Compojure 1.5.1(任意のミドルウェアを使用しないことで)、デフォルトですべてのクエリ文字列を解析しません。ただし、これは以前のバージョンでは異なる可能性があります。
(require '[compojure.core :refer :all])
(require '[clojure.pprint :refer [pprint]])
(defroutes handler
(GET "/" x
(with-out-str (pprint x)))) ;; just a way to receive a pretty printed string response
$ curl localhost:3000/?a=b
{:ssl-client-cert nil,
:protocol "HTTP/1.1",
:remote-addr "127.0.0.1",
:params {}, ;; EMPTY!
:route-params {},
:headers
{"user-agent" "curl/7.47.1", "accept" "*/*", "host" "localhost:3000"},
:server-port 3000,
:content-length nil,
:compojure/route [:get "/"],
:content-type nil,
:character-encoding nil,
:uri "/",
:server-name "localhost",
:query-string "a=b", ;; UNPARSED QUERY STRING
:body
#object[org.eclipse.jetty.server.HttpInputOverHTTP 0x6756d3a3 "[email protected]"],
:scheme :http,
:request-method :get}
リングは、クエリ文字列を解析してのparams - キーの下に、それのハッシュマップを作成ring.params.wrap-params
ミドルウェアを提供しています:
(defroutes handler
(wrap-params (GET "/" x
(prn-str (:params x)))))
$ curl localhost:3000/?a=55
{"a" "55"}
Additionaly ring.params.wrap-params
を使用することができます。
(defroutes handler
(wrap-params (wrap-keyword-params (GET "/" x
(prn-str (:params x))))))
$ curl localhost:3000/?a=55
{:a "55"}
ミドルウェアを使用していますか? 'ring.middleware.params' –