uploaded http-client

5 views
Skip to first unread message

dirk

unread,
Jul 10, 2008, 4:14:11 PM7/10/08
to Clojure
Hi,

i would like some feedback (idiomatic code? interface usable?) on:

http://groups.google.com/group/clojure/web/http-client.clj

(http-client/url-do "https://gmail.com" "GET" { :read-timeout
5000 :set-header { "User-Agent" "Clojure-HttpClient/
0.1 } :connect-timeout
1000 :http-proxy "http://proxy.org:8080" } ))

returns a map:

{:return-message "Found", :return-code 302, :header {nil [HTTP/1.1 302
Found], "Server" [GFE/1.3], "Content-Type" [text/html; charset=UTF-8],
"Date" [Thu, 10 Jul 2008 19:31:52 GMT], "Location" [http://
www.google.com], "Content-Length" [218]}, :body [B@bed1e7}

body is a byte array, so you can cast the bytes to utf-8 or a png
depending on the Content-Type.

I had more problems with the java.* libs (lacks of experience i guess)
than with clojure. Clojure rocks!

I stress tested the client somewhat, seems to be stable. Exception
handling is still lacking though....

Cheers,
Dirk

timmy

unread,
Jul 12, 2008, 5:58:10 AM7/12/08
to Clojure


On Jul 10, 10:14 pm, dirk <dirk.vleug...@gmail.com> wrote:
> Hi,
>
> i would like some feedback (idiomatic code? interface usable?) on:
Hi,

Wow, nice! You should definitely add this to clojure-contrib (http://
sourceforge.net/projects/clojure-contrib).
The usage of url-do seems pretty simple. Maybe it could become a bit
simpler by using arity overloading to supply "GET" and {} as default.
I, for myself, prefer keywords over strings as keys in a map or as
flag-args in function-args. But i don't know whether this is common in
general.
And by looking at the code, i see that its pretty driven by the java
API, so nothing to do wrong, IMO. Personally i like it to split big
functions (like url-do) into more smaller ones so that the code
becomes more modular and self documenting.
Clojure provides alternative syntax for `.' and `new' quite some
time. (. obj meth arg) becomes (.meth obj arg) and (new class arg)
becomes (class. arg).

Well done!
Reply all
Reply to author
Forward
0 new messages