Code Shop

A bit of Ruby, a bit of JavaScript, a bit of love...

    • Edit
    • Delete
    • Autopost

    Simple Clojure Http Client

    I'm learning Clojure and needed a simple http client. Here is the one
    I have written using the java libraries.

     
    (import '(java.net URL HttpURLConnection) 
     '(java.io InputStreamReader BufferedReader)) 
     
    (defn http-client-get-content [reader content] 
     (let [line (.readLine reader)] 
     (if (nil? line) 
     content 
     (recur reader (str content "\n" line))))) 
     
    (defn http-client-get [url] 
     (let [connection (.openConnection (URL. url))] 
     (doto connection 
     (.setRequestMethod "GET") 
     (.setDoOutput true) 
     (.setReadTimeout 10000) 
     (.connect)) 
     (http-client-get-content (BufferedReader. (InputStreamReader. 
    (.getInputStream connection))) ""))) 
    
    Tags » clojure code
    • 1 October 2009
    • Views
    • 0 Comments
    • Permalink
    • Favorited 0 Times
    • Tweet

    Comments 0 Comments

    Leave a Comment

  • Abhi Yerra's Posterous

    An entity composed of reality and pseudo-reality. Enjoys coding, news, history, photography.

  • About Abhi Yerra

    An entity composed of reality and pseudo-reality. Enjoys coding, news, history, photography.

  • Subscribe

    Subscribe to this posterous
    Unsubscribe
    Follow this posterous RSS
  • Follow Me

             

Theme created for Posterous by Obox