philipbohun.com

Glojure by Example: URL Parsing

The full net/url package is not in the default map. net:http.NewRequest parses a URL while it builds a request, and the request's URL field holds the pieces.

(let [[req err] (net:http.NewRequest
                  "GET"
                  "https://example.com:8443/a/b?x=1&y=2#top"
                  nil)]
  (println (nil? err))
  (let [u (.URL req)]
    (println (.Scheme u))
    (println (.Host u))
    (println (.Path u))
    (println (.RawQuery u))
    (println (.Fragment u))))

The host includes the port. The fragment is not part of the path.

$ glj url-parsing.glj
true
https
example.com:8443
/a/b
x=1&y=2
top

Next example: Reading Files.