Great question. And great answer. Seriously! I did not know it could be that easy. So an http GET just needs 1 lines!:
(slurp (reader "http://google.com")) (Don't forget: (use 'clojure.java.io) ) Is there an equally easy way to do an http POST? And also a multi-part (including one or more files in the POST)? On 25 Aug, 18:24, Mats Rauhala <mats.rauh...@gmail.com> wrote: > I too stumbled upon this a while ago. I might even say that on some > level it's so simple that there is not much documentation about it, and > at some point it gets 'complex' enough that you should know about java > enough. > > The simplest way is to slurp or spit. slurp reads a file into a string, > and spit writes a string into a file. > > Then there is the with-open macro(?) which opens connections and closes > them when one. The reader and writer opens a java Reader and Writer > classes respectively. (They're interfaces, but those functions try to > figure out what kind of handle you're trying to open). Also the > output-stream and input-stream handle it a bit. > > (with-open [r (reader "http://www.reddit.com")] > (.read r)) > > And to finish this off with a shameless plug; I wrote a blog post about > downloading a random wallpaper from reddit, which handles reading http > content, parsing json and reading/writing binary files. > > http://users.utu.fi/machra/posts/2011-08-24-2-reddit-clojure.html > > -- > Mats Rauhala > MasseR > > application_pgp-signature_part > < 1 KVisLast ned -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en