net:http.Get performs a GET and returns the response plus an error. Copy the body into a builder, then close it. The URL comes from the command line so the program can talk to any server.
net:http.Get
(def url (first *command-line-args*)) (let [[resp err] (net:http.Get url)] (when err (println (.Error err)) (os.Exit 1)) (println (.Status resp)) (let [buf (new strings.Builder)] (io.Copy buf (.Body resp)) (.Close (.Body resp)) (println (str buf))))
This run calls the server from the next example.
$ glj http-client.glj http://127.0.0.1:18081/hello/world 200 OK hello /hello/world
Next example: HTTP Server.
A hands-on tour in the style of Go by Example. Glojure is a Clojure interpreter hosted on Go.