ANN: Async Http Client for Clojure aka ahc-clj

89 views
Skip to first unread message

Hubert Iwaniuk

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

Just release first version of Async Http Client for Clojure.
http://clojars.org/ahc-clj

This is async http client that is backed by Async Http Client http://bit.ly/aUctdM which by default runs on top of Netty.

General documentation on project is available here: http://neotyk.github.com/ahc-clj/
More detailed docs: http://neotyk.github.com/ahc-clj/docs.html
Autodoc: http://neotyk.github.com/ahc-clj/autodoc/
Code: http://github.com/neotyk/ahc-clj

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,
Hubert.

Reply all
Reply to author
Forward
0 new messages