I've written a URI library for Clojure, whose functions work on a
custom Uri type, java.net.URI, java.net.URL, and java.lang.String.
It's intended to make working with URIs less painful. It makes it easy
to get at the pieces of a URI, as well as doing functional updates. In
particular, it makes it easy to deal with query string parameters.

The source and some documentation (in the README) can be found at
https://github.com/wtetzner/exploding-fish.

Example usage:

Access URI pieces:
user> (scheme "http://www.example.com/";)
"http"
user> (scheme (URI. "http://www.example.com/";))
"http"
user> (fragment (URL. "http://www.example.com/#fragment";))
"fragment"
user> (fragment (uri "http://www.example.com/#fragment";))
"fragment"

Uri objects behave like maps, but ensure that the values remain
consistent:
user> (:host (uri "http://www.example.com/";))
"www.example.com"
user> (assoc (uri "http://www.example.com/";) :port 8080)
#<Uri http://www.example.com:8080/>

Make functional updates:
user> (fragment (uri "http://www.example.com/#fragment";) nil)
#<Uri http://www.example.com/>
user> (host "http://www.example.com/#fragment"; "www.bovinegenius.org")
"http://www.bovinegenius.org/#fragment";
user> (fragment (URI. "http://www.example.com/#fragment";) "it-works-
on-
java-uris")
#<URI http://www.example.com/#it-works-on-java-uris>

Working with query string parameters:
user> (params "http://www.test.net/some/path?x=y&a=w&d%20x=m
%3df&a=x&m=2" "a")
["w" "x"]
user> (param "http://www.test.net/some/path?x=y&a=w&d%20x=m
%3df&a=x&m=2" "d x")
"m=f"
user> (param "http://www.test.net/some/path?x=y&a=w&d%20x=m
%3df&a=x&m=2" "d x" "new-value")
"http://www.test.net/some/path?x=y&a=w&d+x=new-value&a=x&m=2";
user> (query-map "http://www.test.net/some/path?x=y&a=w&d%20x=m
%3df&a=x&m=2")
{"x" "y", "a" "x", "d x" "m=f", "m" "2"}

-- 
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

Reply via email to