ANN: Async Http Client for Clojure aka ahc-clj

Skip to first unread message

Hubert Iwaniuk

Jul 14, 2010, 10:45:39 AM7/14/10
to Clojure
Hi *

Just release first version of Async Http Client for Clojure.

This is async http client that is backed by Async Http Client which by default runs on top of Netty.

General documentation on project is available here:
More detailed docs:

Two basic examples of usage:

(let [resp (GET "<your url>" {:query {:param-name "some-value}})
status (:status @resp)
headers (:headers @resp)
body (:body @resp)]
(println (:code status))
(println (apply str (map char body))))

(let [stream (ref #{})
resp (STREAM :get "<your url>"
(fn [state bytes]
(if (not (empty? bytes))
(let [p (apply str (map char bytes))]
(dosync (alter stream conj p)))
(println "Empty body part received."))))]
; do something to @stream
; @resp will not get delivered until streaming is done

In first example resp is a promise that is delivered once response is received.
Second example is showing how to consume a HTTP Stream, note that it is collecting body parts, which is not necessary.
You can provide a callback that will not collect those parts but just acts on one that was currently received.

Next releases should expose more configuration body streaming from client to server, multipart support.

I hope you'll like it,

Reply all
Reply to author
0 new messages