### Install lambdaisland/uri Library Source: https://github.com/lambdaisland/uri/blob/main/README.md Instructions for adding the lambdaisland/uri dependency to Clojure projects using deps.edn or Leiningen's project.clj. ```Clojure lambdaisland/uri {:mvn/version "1.19.155"} ``` ```Clojure [lambdaisland/uri "1.19.155"] ``` -------------------------------- ### Custom Ordering for URI Query Parameters in Clojure Source: https://github.com/lambdaisland/uri/blob/main/README.md Demonstrates how to use `lambdaisland.uri/query-map` with a custom `{:into (ordered-map)}` option to preserve the order of query parameters. This requires the `org.flatland/ordered` dependency to be added to the project. ```Clojure ;; Provide custom ordering for query-map ;; clj -Sdeps '{:deps {org.flatland/ordered {:mvn/version "1.5.7"}}}' (require '[lambdaisland.uri :refer [query-map]] '[flatland.ordered.map :refer [ordered-map]]) (keys (query-map "http://example.com?a=1&b=2&c=3&d=4&e=5&f=6&g=7&h=8&i=9" {:into (ordered-map)})) => (:a :b :c :d :e :f :g :h :i) ``` -------------------------------- ### Accessing URI Components with Keyword Lookup in Clojure Source: https://github.com/lambdaisland/uri/blob/main/README.md Shows that `lambdaisland.uri.URI` instances implement `IFn`, allowing keyword-based lookup of URI components, similar to how Clojure maps are accessed. This provides a convenient way to retrieve specific parts of a URI. ```Clojure ;; URI implements IFn for keyword based lookup, so it's fully ;; interface-compatible with Clojure maps. (:path (uri "http://example.com/foo/bar")) ``` -------------------------------- ### RFC Compliant URI Joining in Clojure Source: https://github.com/lambdaisland/uri/blob/main/README.md Illustrates the `lambdaisland.uri/join` function for combining relative URIs according to RFC standards. It also shows how `join` can coerce different URI types, including `java.net.URI`, for seamless integration. ```Clojure ;; RFC compliant joining of relative URIs (join "//example.com/foo/bar" "./~arne/site/" "../foo.png") ;;=> #lambdaisland/uri "//example.com/foo/~arne/foo.png" ;; Arguments to `join` are coerced, you can pass strings, java.net.URI, or any x ;; for which `(str x)` returns a URI string. (join (java.net.URI. "http://example.com/foo/bar") (uri "./~arne/site/") "../foo.png") ;;=> #lambdaisland/uri "http://example.com/foo/~arne/foo.png" ``` -------------------------------- ### Reading lambdaisland/uri Objects from EDN Source: https://github.com/lambdaisland/uri/blob/main/README.md Explains how to deserialize `lambdaisland/uri` instances from EDN strings using `clojure.edn/read-string` and the provided `lambdaisland.uri/edn-readers`. This allows for persistent storage and retrieval of URI objects. ```Clojure (require '[clojure.edn :as edn]) (edn/read-string {:readers lambdaisland.uri/edn-readers} "#lambdaisland/uri \"http://example.com/foo/~arne/foo.png\"") ``` -------------------------------- ### Create and Modify URIs in Clojure Source: https://github.com/lambdaisland/uri/blob/main/README.md Demonstrates how to create a URI object using `lambdaisland.uri/uri` and modify its components (scheme, host, path, query, fragment, etc.) using `clojure.core/assoc`. The `str` function is used to convert the URI record back into a string. ```Clojure (require '[lambdaisland.uri :refer [uri join]]) ;; uri :: String -> lambdaisland.uri.URI (uri "//example.com/foo/bar") ;;=> #lambdaisland/uri "//example.com/foo/bar" ;; A URI is a record, use assoc to update specific parts ;; Use `str` if you want the URI back as a string (str (assoc (uri "//example.com/foo/bar") :scheme "https" :user "arne" :password "supersecret" :host "lambdaisland.com" :port "3333" :path "/hello/world" :query "q=5" :fragment "section1")) ;;=> "https://arne:supersecret@lambdaisland.com:3333/hello/world?q=5#section1" ``` -------------------------------- ### Handling URI Objects in Babashka/SCI Source: https://github.com/lambdaisland/uri/blob/main/README.md Highlights differences in how `lambdaisland.uri` objects behave in Babashka/SCI compared to standard Clojure/ClojureScript. It provides alternative functions like `uri/uri-str` for string conversion and `clojure.core/get` or keyword as function for accessing components, as direct `str` and `IFn` implementations are not supported in these environments. ```Clojure ;; clojure / clojurescript (str uri) ;; "https://example.com" (uri :host) ;; "example.com" ;; bb (str uri) ;; "{:scheme "https", :domain "example.com", :path ...}" (uri :host) ;; nil (uri/uri-str uri) ;; "https://example.com" (:host uri) ;; "example.com" (get uri :host) ;; "example.com" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.