2011-07-30 4 views
4

내 코드 :Compojure의 경로 PARAMS 손실 정보

$ (checkin-app-handler {:server-port 8080 :server-name "127.0.0.1" :remote-addr "127.0.0.1" :uri "/123" :query-string "foo=1&bar=2" :scheme :http :headers {} :request-method :get}) 
> {:status 200, :headers {"Content-Type" "application/json"}, :body "{\"code\":\"123\",\"params\":{}}"} 

내가 잘못 뭐하는 거지 :

(defn json-response [data & [status]] 
    {:status (or status 200) 
    :headers {"Content-Type" "application/json"} 
    :body (json/generate-string data)}) 

(defroutes checkin-app-handler 
    (GET "/:code" [code & more] (json-response {"code" code "params" more}))) 

나는 REPL에 파일을로드하고이 명령을 실행

에서, PARAMS가 빈 것 같다 ? 나는 쿼리 문자열에서 얻을 필요가 있지만, PARAMS지도는 항상 비어 ..

답변

5

가 PARAMS지도로 구문 분석 쿼리 문자열을 얻으려면, 당신은 PARAMS 미들웨어를 사용해야합니다

(ns n 
    (:require [ring.middleware.params :as rmp])) 

(defroutes checkin-app-routes 
    (GET "" [] ...)) 

(def checkin-app-handler 
    (-> #'checkin-app-routes 
     rmp/wrap-params 
     ; .. other middlewares 
    )) 

var (#'checkin-app-routes)의 사용은 꼭 필요한 것은 아니지만 경로를 재정의 할 때 경로를 폐쇄하고 미들웨어 내부를 감싸며 변경 사항을 선택합니다.

IOW

당신은 또한

(def checkin-app-handler 
    (-> checkin-app-routes 
     rmp/wrap-params 
     ; .. other middlewares 
    )) 

을 쓸 수 있지만, 대화 형 경로를 재정의 할 때 다음, 당신은 너무 핸들러를 재정의해야합니다.