Search code examples
clojurehttp-kit

httpkit-fake does not intercept url build with passed parameters


How can I have with-fake-http intercept an http/get request containing :query-params. The following code produces an exception

 (require                                                                                                                                                                                                                                                                      
            '[org.httpkit.client :as http]                                                                                                                                                                                                                                      
            '[org.httpkit.fake :refer :all]                                                                                                                                                                                                                                     
            )      


(with-fake-http ["localhost?q=hello" "hello param"]                                                                                                                                                                                                                             
  (println @(http/get "localhost" :query-params {:q "hello"})))   

CompilerException java.lang.IllegalArgumentException: Attempted to perform GET on unregistered URL localhost and real HTTP requests are disabled., compiling:(web/db_test.clj:57:1)

Thanks for your help.


Solution

  • Instead of the String "localhost?q=hello", you can provide a map with the keys :url and :query-params

    (with-fake-http 
        [{:query-params {:q "hello"}, :url "localhost"} "hello param"]
        (println @(http/get "localhost" {:query-params {:q "hello"}})))