Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added query support to request and resourcefully functions.

  • Loading branch information...
commit 1d0f64a5a2900ddacff23d3c459978f7028cc05a 1 parent 1c33d77
@Raynes Raynes authored
Showing with 12 additions and 4 deletions.
  1. +9 −2 src/clojure_http/client.clj
  2. +3 −2 src/clojure_http/resourcefully.clj
View
11 src/clojure_http/client.clj
@@ -105,12 +105,19 @@ by a server."
#^String (as-str (val cookie))))
cookie-map)))
+(defn- queryify
+ "Takes a map of query parameters and turns them into a query string."
+ [url query-map]
+ (if (seq query-map)
+ (apply str url "?" (interpose "&" (for [[k v] query-map] (str k "=" v))))
+ url))
+
(defn request
"Perform an HTTP request on URL u."
- [u & [method headers cookies body]]
+ [u & [method headers cookies querys body]]
;; This function *should* throw an exception on non-HTTP URLs.
;; This will happen if the cast fails.
- (let [u (url u)
+ (let [u (url (queryify u querys))
#^HttpURLConnection connection
(cast HttpURLConnection (.openConnection u))
method (.toUpperCase #^String (as-str (or method
View
5 src/clojure_http/resourcefully.clj
@@ -37,11 +37,12 @@
[method]
`(defn ~method
~(str "Perform HTTP " method " request to url u with specified headers
-map. Cookies will be saved if inside with-cookies block.")
- [u# & [headers# body#]]
+and query map. Cookies will be saved if inside with-cookies block.")
+ [u# & [headers# querys# body#]]
(let [response# (save-cookies (client/request u# ~(str method)
headers# (if *cookies*
@*cookies*)
+ querys#
body#))]
(if (error? response#)
(throw (java.io.IOException. (error-message response#)))
Please sign in to comment.
Something went wrong with that request. Please try again.