Clojure building of URL from constituent parts

后端 未结 5 1195
余生分开走
余生分开走 2021-02-07 17:46

In Python I would do the following:

>>> q = urllib.urlencode({\"q\": \"clojure url\"})
>>> q
\'q=clojure+url\'

>>> url = \"http://sta         


        
5条回答
  •  灰色年华
    2021-02-07 18:43

    This is the exact REPL equivalent of your python session, using clj-http.

    user=> (require ['clj-http.client :as 'client])
    nil
    user=> (str "http://stackoverflow.com/search?"
    user=*      (client/generate-query-string {"q" "clojure url"}))
    "http://stackoverflow.com/search?q=clojure+url"
    

    but clj-http makes it even easier:

    user=> (client/get "http://stackoverflow.com/search?"
    user=*             {:query-params {"q" "clojure url"}})
    ... ...
    

    assuming that you want to perform a GET request, that is.

提交回复
热议问题